What is the most elegant way to get a set of items by index from a collection?

后端 未结 14 2043
梦如初夏
梦如初夏 2020-12-13 04:57

Given

IList indexes;
ICollection collection;

What is the most elegant way to extract all T in

14条回答
  •  情话喂你
    2020-12-13 05:48

        public static IEnumerable WhereIndexes(this IEnumerable collection, IEnumerable indexes)
        {
            IList l = new List(collection);
            foreach (var index in indexes)
            {
                yield return l[index]; 
            }
        }
    

提交回复
热议问题