【发布时间】:2015-02-27 10:25:51
【问题描述】:
有一个 List<int> 包含一些数字。我随机选择一个索引,将单独处理(称为 master)。现在,我想排除这个特定索引,并获取 List 的所有其他元素(称它们为 slave)。
var items = new List<int> { 55, 66, 77, 88, 99 };
int MasterIndex = new Random().Next(0, items .Count);
var master = items.Skip(MasterIndex).First();
// How to get the other items into another List<int> now?
/* -- items.Join;
-- items.Select;
-- items.Except */
Join、Select、Except - 任何一个,以及如何?
编辑:无法从原始列表中删除任何项目,否则我必须保留两个列表。
【问题讨论】:
-
我知道这是一个老问题,但可能值得考虑替换“主”和“从”这两个词——由于它们与奴隶制。一些建议的替代方案:en.wikipedia.org/wiki/Master/…
-
公平点@Lou
标签: c# .net linq list enumerable