3
想象一下,除了序列exceptions
中包含的元素和单个元素otherException
之外,您希望选择一个序列all
的所有元素。将单个元素添加到表达式的序列
有没有比这更好的方法?我想避免创建新的数组,但我无法找到序列中的一个方法,它与单个元素连接。
all.Except(exceptions.Concat(new int[] { otherException }));
完整的源代码的完整性的缘故:
var all = Enumerable.Range(1, 5);
int[] exceptions = { 1, 3 };
int otherException = 2;
var result = all.Except(exceptions.Concat(new int[] { otherException }));
是,扩展方法将是更好的方式去。 – Axarydax 2009-12-17 11:30:56