我相信有更好的方法来写这段代码,但我现在脑袋一片空白。
int num = 0;
using(var db = new TestDB())
{
num = db.Table.Where(x => x.FavoriteSport == "Baseball" &&
(x.FavoriteColor == "Green" ||
x.FavoriteColor == "Blue" ||
x.FavoriteColor == "Red")).Count();
}
return num;
有没有更好的方法来写OR
语句?我已经尝试了以下几种方法:
x.FavoriteColor == "Green" || "Blue" || "Red"
但编译器显示“运算符||不能应用于类型为'bool'和'string'的操作数”。非常感谢您的帮助。