次のコードがあり、linq に変換したいと考えています。外部 foreach 内の 2 つの foreach ループを考慮して、それは可能ですか? 現在、内部の foreach ループを linq に変換することしかできませんでしたが、それでもコードが非常に長いため、もっと短くなると思います。
List<complexType> listOfComplex = ...some list...
List<complexType> newListOfCOmplex = new List<complexType>();
SomeObjectType someObject = ...some object...
foreach(var cT in listOfComplex)
{
var someObjectPropertyValue = someObject.property.FirstOrDefault(a=>a.value == smth);
if(someObjectPropertyValue == null)
{
return null;
}
var t = someObjectPropertyValue.Something.AnotherSomethin;
if(t==null)
{
newListOfCOmplex.Add(cT);
continue;
}
var collectionFirst = t.Where(s=>s.value == firstValue);
foreach (var f in collectionFirst)
{
someOtherMethod(f);
}
newListOfCOmplex.Add(cT);
var collectionSecond = t.Where(s=>s.value == secondValue);
foreach (var s in collectionSecond)
{
someOtherMethod(s);
}
}