यह यह करना चाहिए। मैंने विशेष रूप से इसके लिए एक परीक्षण का निर्माण नहीं किया है।
var nextProducts = from item1 in recommendations.Select((rec, idx) => new { Rec = rec, Index = idx })
join item2 in recommendations.Select((rec, idx) => new { Rec = rec, Index = idx })
on item1.Index equals item2.Index - 1
where item1.Rec.Products.Any(p => p.Code == "A")
&& item1.Rec.Products.Any(p => p.Code == "B")
select item2.Rec;
आप दोनों रिकॉर्ड की जरूरत है, तो चयन बयान
select new { MatchingItem = item1.Rec, NextItem = item2.Rec };
हो सकता है लेकिन तब आप उससे मिलते-जुलते आइटम सूची में अंतिम आइटम जा रहा है के लिए खाते में करने के लिए एक समूह ऐसा करने के लिए होगा (वहाँ होगा उस मामले में कोई अगली वस्तु न हो)।
var nextProducts = from item1 in recommendations.Select((rec, idx) => new { Rec = rec, Index = idx })
join item2 in recommendations.Select((rec, idx) => new { Rec = rec, Index = idx })
on item1.Index equals item2.Index - 1
into groupjoin
from i2 in groupjoin.DefaultIfEmpty()
where item1.Rec.Products.Any(p => p.Code == "A")
&& item1.Rec.Products.Any(p => p.Code == "B")
select new { MatchingItem = item1.Rec, NextItem = i2 == null ? null : i2.Rec };
कोड मैं किया परीक्षण स्ट्रिंग की एक सूची के साथ कुछ ऐसा ही था।
List<string> list = new List<string>() { "a", "b", "c", "a", "d", "a", "e" };
var query = from item1 in list.Select((s, idx) => new { Item = s, Index = idx })
join item2 in list.Select((s, idx) => new { Item = s, Index = idx })
on item1.Index equals item2.Index - 1
where item1.Item == "a"
select item2.Item;
जो बी, डी, और ई देता है।
MyList.SkipWhile(item => item.Name != "someName").Skip(1).FirstOrDefault()
एक पहले जवाब Skip(1).Take(1)
जो काम करता है का उपयोग करता है, लेकिन एक परिणाम की एक सूची देता है:
+1 लैम्ब्डा वाक्य रचना के उपयोग के लिए रिवर्स() काम नहीं करेगा। –