我遇到了下面的linq查询,无法理解它。它似乎有2条from
语句。
var foo = (from XmlNode listingSource in listingSources
from idxRule in idxRules
where idxRule.IDXRuleID == idxRuleId && idxRule.IsEnabled && idxRule.ListingSourceID == TrioXml.GetInt32Value(listingSource, "ListingSourceID")
select TrioXml.GetInt32Value(listingSource, "ListingSourceID"));
2个from
语句是否表示内部和外部for循环?如果我将其重写为循环,会是这样吗?
var foo = new List<int>;
foreach (XmlNode listingSource in listingSources) {
foreach (IDXRule idxRule in idxRules) {
if (idxRule.IDXRuleID == idxRuleId && idxRule.IsEnabled && idxRule.ListingSourceID == TrioXml.GetInt32Value(listingSource, "ListingSourceID")) {
foo.Add(TrioXml.GetInt32Value(listingSource, "ListingSourceID"));
}
}
}