c# get class name of object code example
Example 1: c# get object property value by name
return car.GetType().GetProperty(propertyName).GetValue(car, null);
Example 2: c# get class name by type
typeof(T).Name
typeof(T).FullName
typeof(T).Namespace
Example 3: C# get object property name
using System.Reflection;
PropertyInfo[] propertyInfos;
propertyInfos = typeof(MyClass).GetProperties(BindingFlags.Public |
BindingFlags.Static);
Array.Sort(propertyInfos,
delegate(PropertyInfo propertyInfo1, PropertyInfo propertyInfo2)
{ return propertyInfo1.Name.CompareTo(propertyInfo2.Name); });
foreach (PropertyInfo propertyInfo in propertyInfos)
{
Console.WriteLine(propertyInfo.Name);
}
Example 4: c# get class name as string
public static class ClassName
{
public static void PrintName => Console.WriteLine(nameof(ClassName));
}