If I write:
var type = typeof(List<string>);
Console.WriteLine(type.Name);
It will write:
List`1
I want it to write just:
List
How can I do that?
Is there a smarter way to do it without having to use Substring or similar string manipulation functions?
No, it makes perfect sense for it to include the generic arity in the name – because it’s part of what makes the name unique (along with assembly and namespace, of course).
Put it this way:
System.NullableandSystem.Nullable<T>are very different types. It’s not expected that you’d want to confuse the two… so if you want to lose information, you’re going to have to work to do it. It’s not very hard, of course, and can be put in a helper method:Then: