© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
46 replies
lukkasz323

❔ ✅ I can't convert List<BaseClass> to List<T> where T: BaseClass.

I have a
List<List<Component>>
List<List<Component>>
.
Component
Component
is a base class, and each item in this outer list is actually a List with different sub-classes of
Component
Component
. At run-time I expect it to look like this:

List<List<Component>>:
  List<SubComponentA>
  List<SubComponentB>
  List<SubComponentC>
List<List<Component>>:
  List<SubComponentA>
  List<SubComponentB>
  List<SubComponentC>

Everything works nicely besides this - I can't find a way to get for example
List<SubComponentA>
List<SubComponentA>
from the outer list. Here's my current attempt:
image.png
image.png
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Convert List to IList
C#CC# / help
3y ago
✅ Cannot convert List<MyClass> to List<object>
C#CC# / help
9mo ago
I can't JSON to List ;_; [Answered]
C#CC# / help
4y ago
Derived class , BaseClass, Dictionary
C#CC# / help
2y ago