Kunjahamed P

Kunjahamed P

  • NA
  • 376
  • 39.8k

How to getting its own class name(Class and List obejct)

Aug 12 2020 5:33 AM
If I have a class called sample, is there a way(Common) of retrieving "sample" as a string?
  1. public class sample  
  2. {  
  3. public int MyProperty { getset; }  
  4. public int MyProperty2 { getset; }  
  5. public string MyProperty3 { getset; }  
  6. }  
  7. sample sampleClass = new sample();  
  8. List<sample> sampleClassList = new List<sample>();  
  9. var name = sampleClass.GetType().Name;  
  10. var name2 = sampleClassList.GetType().Name;  
In here class object class name correct but list object not get. is there any common way to get class name of object (List and Class)

Answers (3)