我有一些我真的不喜歡的代碼的一部分,如果有可能以某種方式簡化它 - 會非常好。簡化LINQ表達式
A a; // I want to get rid of this variable
if((a = collection.FirstOrDefault(x => x.Field == null)) != null)
{
throw new ScriptException("{0}", a.y); //I need to access other field of the object here, that's why I had to declare a variable outside of the expression
}
你需要變量,除非你想執行兩次表達式 – Jonesopolis
@Jonesy這就是我所害怕的。 – Anarion
@Aarreion我想你會害怕'TryParse'和'Tryxxx'模式。 –