-1
返回true请看下面的代码:。所有的Linq空收集
static void Main(string[] args)
{
List<string> items = new List<string>();
string result = null;
if(items.All(o => o == "ABC"))
{
result = "All";
}
else if(items.Any(o => o == "XYZ"))
{
result = "Any";
}
Console.WriteLine(result);
Console.Read();
}
这版画 “全部”。
为什么一个空列表满足 “所有” 的条件,其中o == "ABC"
看看源代码[here](http://referencesource.microsoft.com/#System.Core/System/Linq/Enumerable.cs,be4bfd025bd2724c,references) –
_Why_是主观的,不是吗?杯子是半满的还是半空的? “全部”满足你的条件,因为没有。如果列表为空,您可以随时检查。 –
我认为你需要以相反的方式思考它。 '.All(...)'是'true',只要不存在'false'。如果列表为空,则不存在“false”,因此它是“true”。 – Enigmativity