Blankman Blankman - 1 year ago 77
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?

Answer Source

Just use .Name like this:


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download