I want to write common function which get all or single class property name
public class MyClass
{
public int TemplateId { get; set; }
public int TemplateCategoryId { get; set; }
}
Example: In other method I need to call
var propertyName = MyClass.TemplateId.GetPrertyName(); // will Return TemplateId
How can I make it?
Using the c# 6 nameof
operator, you can write:
nameof(MyClass.TemplateId);
More details can be found here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.