Blankman Blankman - 4 months ago 20
C# Question

how to I get the class name when I am passing in a generic in my method?

My method looks like:

public string DoObjectProperties<T>(T obj, string text)


Now from within the method, I need to get the string value of the class name that i pass into the method's 'obj' parameter.

So if I pass in the User object, I need the text 'user'.

To get the properties I am using:

How can I get the classes name?


Just use .Name like this:


This gives for example "String", there's also .FullName which would give "System.String"