هل هناك طريقة لتسوية .net ilookup إلى قائمة ؟

StackOverflow https://stackoverflow.com/questions/2323369

  •  22-09-2019
  •  | 
  •  

سؤال

هل هناك طريقة سريعة للحصول على تسطيح List<TElement> من ILookup<TKey, TElement> التي تم إنشاؤها من IEnumerable<TElement> امتداد؟


تم تحديثه مع مثال

List<int> list = new List<int>();
var lookup = list.ToLookup(key => key);
list = lookup.?? // How to convert the lookup back to the list
هل كانت مفيدة؟

المحلول

lookup.SelectMany( x => x ).ToList()

التحول إلى ILookup والعودة مرة أخرى على الأرجح قد غير الأمر ، ولكن.

نصائح أخرى

لست متأكدًا مما إذا كان هذا هو ما أنت عليه. إلى عن على Dictionary<> إلى List<>

List<TElement> list iLookUp.Values.ToList<TElement>();

من List<> إلى Dictionary<>

var dict = list.Cast<TElement>().ToDictionary(t => t.Id, t => t.Description);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top