简体   繁体   English

如何在 C# “object.equals”中使用“或”(|)运算符

[英]How do I use “or” (|) operator in C# “object.equals”

var controllingContext = _context.Inventaris.Include(i => i.Artkl).Include(i => i.Status).Where(x => x.StatusId.Equals(stat[0] | stat[1]));

I am trying to add an or operator in C# to the object.equals method this was working while I didn't have the or operator in there and it was just checking for 1 item but now I added the or operator and it doesn't work anymore.我正在尝试将 C# 中的 or 运算符添加到 object.equals 方法中,当我没有 or 运算符并且它只是检查 1 项但现在我添加了 or 运算符但它没有工作了。 Any help would be greatly appreciated任何帮助将不胜感激

If I understood correctly, you want to filter StatusId equals stat[0] or stat[1] .如果我理解正确,您想过滤StatusId等于stat[0]stat[1] If so you just need to use OR( || ) operator as following:如果是这样,您只需要使用 OR( || ) 运算符,如下所示:

.Where(x => x.StatusId.Equals(stat[0]) || x.StatusId.Equals(stat[1]));

See LINQ FilteringLINQ 滤波

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Object.Equals是虚拟的,但是Object.operator ==不在C#中使用它吗? - Object.Equals is virtual, but Object.operator== does not use it in C#? C#operator ==,StringBuilder.Equals,Object.Equals和Object.ReferenceEquals之间的差异 - C# Differences between operator ==, StringBuilder.Equals, Object.Equals and Object.ReferenceEquals C#:静态object.Equals如何检查是否相等? - C#: How does the static object.Equals check for equality? C#中的Object.Equals澄清? - Object.Equals clarification in C#? 带有多个或条件的 C# Object.Equals() - C# Object.Equals() with multiple or conditions 如何告诉我的抽象类的mock / stub使用它的Object.Equals()重写? - How do I tell my mock/stub of an abstract class to use its override of Object.Equals()? C#运算符重载:Object.Equals(object o)和Object.GetHashCode() - C# operator overloading: Object.Equals(object o) & Object.GetHashCode() 有效的C#:覆盖Object.Equals(),不管是不是? - Effective C#: Overriding Object.Equals(), yay or nay? 如何仅在不破坏现有 Object.Equals() 的情况下检查两个对象的属性是否相等? - How do I check if two Objects are equal in terms of their properties only without breaking the existing Object.Equals()? 如何在C#中覆盖接口的equals运算符==? - How do I override the equals operator == for an Interface in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM