我有一个返回操作系统属性列表的方法。我希望循环遍历每个属性并进行一些处理。所有属性都是字符串类型。
如何循环遍历该对象? C#
如何循环遍历该对象? C#
// test1 and test2 so you can see a simple example of the properties - although these are not part of the question
String test1 = OS_Result.OSResultStruct.OSBuild;
String test2 = OS_Result.OSResultStruct.OSMajor;
// here is what i would like to be able to do
foreach (string s in OS_Result.OSResultStruct)
{
// get the string and do some work....
string test = s;
//......
}
GetValue(OS_Result.OSResultStruct, null)
。 - Sergey Kalinichenkoprop.Name
了。 - Sergey KalinichenkoIEnumerable<KeyValuePair<string,T>>
,以便使用您方法的用户可以访问属性名称,而不仅仅是属性值。 - Sergey Kalinichenko