/ Published in: C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
struct Employee { public string name; public int age; public string location; }; static void Main(string[] args) { Employee employee; employee.name = "Jim Smith"; employee.age = 35; employee.location = "California"; Type t = employee.GetType(); System.Reflection.FieldInfo [] fields = t.GetFields(System.Reflection.BindingFlags.Instance|System.Reflection.BindingFlags.Public); foreach (System.Reflection.FieldInfo field in fields) { Console.WriteLine(field.Name + " = " + field.GetValue(employee)); } // Expected output: // name = Jim Smith // age = 35 // location = California } // main
URL: http://www.eggheadcafe.com/conversation.aspx?messageid=29838045&threadid=29837893