use*_*998 2 c# lambda operators
我这里有这个代码:
public Model.task GetDelete(int qno , int aid , int tid)
{
return context.questions.FirstOrDefault(a => a.QuestionNo = qno & a.ActivityID == aid & a.TaskID == tid);
}
Run Code Online (Sandbox Code Playgroud)
我需要适合所有 3 个 id,上面有一个错误,我是编程新手,我怎样才能避免这个错误?基本上我需要检查 3 个 id,这可能吗?有错误说
运算符“&&”不能应用于“int”和“bool”类型的操作数
您在 lambda 中有赋值运算符=,您需要使用相等运算符==,例如:
context.questions.FirstOrDefault(a => a.QuestionNo == qno & a.ActivityID == aid & a.TaskID == tid);
//here ^^
Run Code Online (Sandbox Code Playgroud)
你会得到一个错误:
运算符“&&”不能应用于“int”和“bool”类型的操作数
因为赋值运算符返回int您的情况下的值,而右侧的相等运算符需要 bool。
此处短路运算符的使用是可选的,如果您的属性没有任何
副作用&&并且它们返回原始类型或类型,它们不会改变 lambda 的行为,并且不会覆盖引入副作用的运算符。==
| 归档时间: |
|
| 查看次数: |
4244 次 |
| 最近记录: |