© 2026 Hedgehog Software, LLC
Twitter
GitHub
Discord
System
Light
Dark
More
Communities
Docs
About
Terms
Privacy
Search
Star
Feedback
Setup for Free
Get implementation out of list of interfaces without explicit casting - C#
C
C#
•
4y ago
•
8 replies
Instinct
Get implementation out of list of interfaces without explicit casting
Merry Christmas
!
Trying to get the instance implementation out of a list of an interface
, without explicitly casting the item of the list to the desired class
, as per
https://sharplab.io/#v2:CYLg1APgAgTAjAWAFBQAwAIpwCwG5nIAyAlgM4AuAPAJIBiA9vQHzoA2Z56AvOgHYCmAdwAUASmQBvZOhl8h6AIJiANHMHoAQmOQBffEmQB6Q+gAqACzLorAM2IDkAYXq9S9VvwB0AdQBOxcn5hdgoAbVQAXU8AcX5yaldyAENeAGN+SgUmMU8AZXoAW35RfSwATmCOULgo2PjElPTKDWzRTwt7AHMSgiRjTQBXTkF6AdZgdF8k8nN+X3QkqGx0UgAHflTiGwBPLvQZ/n3t9ZX6fctSdFT6YEORsYnyAd9edAA3JPZgIxMQ8nDanEEhRGkE2vkij82FUajEgQ00mD2pZeJ1erBFOgQOg6IxJNJZFAAMyYOAYCGHLgsABEFOp+gJMlMOIY9Dh9RBiMopla3BYMzI+h06JgmixLLxSCkSFkmBJWAwHVRfPQ1IFqPpvVlzNxbLqwOSXJ5YhVAtIQt69kCvhsSXSEvo+JlsmZ+oRTWNonQglmvkOzOxsAtSCAA==
This gives the wanted output however it misses the casting point
https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwAICYCMBYAUKgBgAJVMAWAbjzwBkBLAZ2AB4BJAMQHtOA+IgG0bAiAXiJQApgHcAFAEo8AbzxFV46UQCC8mOqlEAQvLwBfKrjwBhTlAad+EgHQB1MHWASZMwUwDaBAF0iAEMGLTkAQkcAZU4AWwk5c1IATi8fYF9MINDDSMcAFQALOigAcyTqfHQtIhAiDm4lFTVUAGYSTGJYhNE+ACIeiX7zEyqMQzqGrk5m3DUSDtJiYtKyvqJ+4BLykdMq0o8wADNggGMJaabcZVwTIA===
The questions are
:
How do you implicitly convert class A and B to generic T
?
Is there another way to represent a list that can contain multiple implementations
? If so then may you show a snippet
, reference to some article
/keyword or query to google
?
C#
Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
62,470
Members
View on Discord
Resources
ModelContextProtocol
ModelContextProtocol
MCP Server
Similar Threads
Was this page helpful?
Yes
No
Recent Announcements
Similar Threads
✅ Explicit interface implementation
C
C# / help
2y ago
Generics without Casting
C
C# / help
3y ago
✅ ObjectDisposedException without explicit trace
C
C# / help
2y ago
Static Classes without Implementation
C
C# / help
2y ago