public bool IsNewUser(int id)
{
var data= DataContext.Employee.Where(e=>e.id==id).FirstorDefault();
if(data==null)
return true;
return false;
}
我如何在 C# 的单行中使用 ??
或其他东西编写上述函数逻辑?我确信那一定是可能的,只是现在还想不起来……谢谢
最佳答案
这不是使用 ??
的情况,但这应该有所帮助:
public bool IsNewUser(int id)
{
return !DataContext.Employee.Any(e => e.id == id);
}
??
会被用来做这样的事情:
public Employee GetEmployeeOrNew(int id)
{
return DataContext.Employee.Where(e => e.id == id).FirstorDefault() ?? new Employee();
}
关于c# - 如何在 C# 中的一行中编写 bool 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4630282/