我明白了implicitly-typed local variables must be initialized
。
我知道那result
将是一个IList
,所以我能以某种方式说 varresult
将是一个IList
吗?
var result; //initialize to something
if( x < 0)
{
result = (from s in context.someEntity
where s.somecolumn = x
select new { c1 = s.c1,c2=s.c2}).ToList();
}
if(x >= 0)
{
result = (from s in context.someEntity
where s.someOtherColumn = x
select new { c1 = s.c1,c2=s.c2}).ToList();
}
foreach(var y in result)
{
//do something . UPDATE 1: Retrieve y.c1, y.c2
}