mercredi 31 mars 2021

C# reflection: how to get the item type of a List? [duplicate]

Suppose I have a "Type mytype", and if I do "mytype.ToString()", I get "System.Collections.Generic.List`1[Example1.Employee]", how do I get the list item type, which is "Example1.Employee"? Do I have to parse this string to get this list item type? Is there a more elegant way, such as "mytype.ItemType"?

Also, why is there a "`1" appendix at the end of "System.Collections.Generic.List`1"?

And, why is there a "`2" at the end of "System.Collections.Generic.Dictionary`2"?





Aucun commentaire:

Enregistrer un commentaire