打印对象:
foreach (PropertyDescriptor descriptor in TypeDescriptor.GetProperties(obj)) { string name = descriptor.Name; object val = descriptor.GetValue(obj); Console.WriteLine("name:{0}=value:{1}", name, val); }
数组遍历:
ArrayList farm=new ArrayList(); farm.Add("加州农场"); farm.Add("加利福利亚农场"); foreach(string farmName in farm){ Console.WriteLine(farmName); }
原文:https://www.cnblogs.com/lichihua/p/10914629.html