获取除C中特定值以外的所有数组元素
答
像这样将工作:
// remove where not is "1"
string[] arr = new[] { "1", "2", "3" };
string[] all = arr.Where(x => (x != "1")).ToArray();
// or remove by index
int numIndex = Array.IndexOf(arr, "1");
arr = arr.Where((val, idx) => idx != numIndex).ToArray();
答
你可以这样做
public T[] Except<T>(T[] array, T specificValue) where T : IComparable {
return array.Where<T>(val => val.CompareTo(specificValue) != 0).ToArray();
}
你尝试过什么码? – Hristo
'arr.Except(x => somecondition).ToArray()' –
@LeiYang除了需要一个IEnumerable而不是一个Func。 –