asp.net - How can I count number of data members at runtime in C#? -
this question has answer here:
- how list of properties of class? 9 answers
i have following class in c#. how can count number of data members @ runtime?
public static class abc { public static string a; public static string b; public static string c; }
bascially, have iterate each datamember , pass function 1 one assign value. thats why need this.
if not possible, there other way same
here 1 way it:
var count = typeof(abc).getfields().length;
each element of array returned getfields
corresponds data member. in addition getting count, can further examine each field - name, check type , on. can use fieldinfo
objects and/or set fields of target class.
Comments
Post a Comment