在这里,我对我需要使用的返回类型感到困惑:
public IEnumerable<Employee> GetEmployee123()
{
try
{
var x = from n in db.Employees select n;
return x;
}
catch (Exception ex)
{
Business_Dll.Model.Errorhandlecls
.ExceptionLogging.SendErrorToText(ex);
}
}
答案 0 :(得分:1)
我通常避免从方法返回空值而更喜欢使用Enumerable.Empty。这样就可以避免空值检查并安全地将此方法与其他方法(例如LINQ)一起使用。
public IEnumerable<Employee> GetEmployee123()
{
try
{
var x = from n in db.Employees select n;
return x;
}
catch (Exception ex)
{
Business_Dll.Model.Errorhandlecls
.ExceptionLogging.SendErrorToText(ex);
return Enumerable.Empty<Employee>();
}
}