我知道不允许将匿名类型设置为null,但是我该如何解决这个问题:
var products = null; //this cant be null, but somehow it must be declared in this outer scope, and not only inside the try-catch scope
try
{
products = (from p in repository.Products
select new { p.Product, p.ProductName }).ToList();
}
catch (Exception e)
{
return;
}
Console.WriteLine(products.FirstOrDefault().ProductName)