利用Q& As处理循环对象的属性(Loop Through An Objects Properties In C#和Using LINQ to loop through inner class properties in outer class collection),您可以在哪里:
你好吗:
请在下面找到相关课程的粗略地图。
我一直试图使用LINQ查询但没有成功。 Konrad Kokosa提供的answer大部分都在那里。任何想法或指导将不胜感激。
class MainClass {
List<Class1> listObj1
}
class Class1 {
// a number of fields including...
int PropertyA { get; set; }
int PropertyB { get; set; }
Dictionary<int, Class2> dictObj2 { get; set; }
}
class Class2 {
// a number of fields all of type double...
double MeasurementA { get; set; }
double MeasurementB { get; set; }
double MeasurementC { get; set; }
}
答案 0 :(得分:0)
Just Loop:
foreach(var cls1 in listObj1)
{
int tempA = cls1.PropertyA;
foreach(var cls2 in cls1.dictObj2)
{
double tempB = cls2.MeasurementB;
}
}
过滤/高效循环:
foreach(var cls1 in listObj1.Where(c1=> c1.PropertyA > 5 && c1.PropertyB > 3))
{
int tempA = cls1.PropertyA;
foreach(var cls2 in cls1.dictObj2.Where(c2=> c2.MeasurementA >= 10))
{
double tempB = cls2.MeasurementB;
}
}