views:

50

answers:

2

I want to access all public variables declared in the class sequentially. Which is the best way to do it?

A: 
typeof(MyClass).GetMembers()
Alex Reitbort
He just wants the public _variables_, not the methods and functions.
Oded
+8  A: 
FieldInfo [] fields = typeof(YourClass).GetFields(BindingFlags.Public | BindingFlags.Instance);

this will return FieldInfo on all the public fields

monkey_p
Tip: You might need (BindingFlags.Public | BindingFlags.Instance); if the class is not static.
Jason Evans
Ah, ye, you are right
monkey_p