原文地址:http://social.microsoft.com/Forums/en-US/660f2d84-b63a-4d24-8e42-3aa999a28864
using System.Reflection
class Program
{
static void Main(string[] args)
{
Xstruct x = new Xstruct("value1", "value2", "value3", "value4");
foreach (FieldInfo fieldInfo in x.GetType().GetFields())
Console.WriteLine("{0}:{1}", fieldInfo.Name, fieldInfo.GetValue(x));
Console.ReadKey();
}
}
public struct Xstruct
{
public string filed1;
public string filed2;
public string filed3;
public string filed4;
public Xstruct(string filed1, string filed2, string filed3, string filed4)
{
this.filed1 = filed1;
this.filed2 = filed2;
this.filed3 = filed3;
this.filed4 = filed4;
}
}
// ------- output --------
// filed1:value1
// filed2:value2
// filed3:value3
// filed4:value4