Ad

How To Extract Property Names From Custom Class In C#

- 1 answer

I am making function for exporting table to .csv file.

I have List where T is custom class.

I need property names of T for columns in .csv file.

How can I extract them to other List ?

Ad

Answer

You can use reflection:

var propertyNames = typeof(T).GetProperties()
      .Select(p => p.Name));
Ad
source: stackoverflow.com
Ad