output member variables values from a class

    hello, im looking for a way to systematically output the values of a class without having the manually type each one in

so for example class Foo{

int a;

float b;

string c


some function that will output:

a = 2

b = 9.1

c = pancake


so basically a function that will loop through each variable in the class and output its name and current value, any help with this would be great, thanks



Chances are at least one if not more other people are going to tell you to use reflection to do this, and that may be what you want, however a more propor way to do something like this would probably to overload the ToString method for the object, or to

Hi,What should the format of your output be? A string, XML, a dictionary, a custom object, ect? Additionally, how are you expecting the value  of a collection to be output or are you solely interested in an int, float, and a string? Certainly,

I assume, since you mentioned not wanting to type  in the properties that you are looking for a generic solution that would work for any class. Assuming you may or may not know the members or even have control of the code for the class. In that case using reflection is really your only option. You would do something like this:privatevoid ReflectProperties(Object obj)