asp.net - How can I count number of data members at runtime in C#? -


this question has answer here:

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.

demo on ideone.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -