Is there a way to list all Variables (Fields) of a class in C#.
If yes than could someone give me some examples how to save them in a List and get them maybe using Anonymous Types (var).
Is there a way to list all Variables (Fields) of a class in C#.
Share
Your question isn’t perfectly clear. It sounds like you want the values of the fields for a given instance of your class:
Note that
fieldValuesisList<object>. Here,foois an existing instance of your class.If you want
publicand non-publicfields, you need to change the binding flags viaIf you merely want the names:
Here,
Foois the name of your class.