C# 我能表演一个“表演”吗;或;LINQ中的操作到对象?

C# 我能表演一个“表演”吗;或;LINQ中的操作到对象?,c#,linq,C#,Linq,事实证明,在谷歌上查找LINQ and Or有些困难,所以我来了 我想提出以下建议: (from creditCard in AvailableCreditCards where creditCard.BillToName.ToLowerInvariant().Contains(txtFilter.Text.ToLowerInvariant()) **or creditCard.CardNumber.().Contains(txtFilter.Text)** orderby creditCar

事实证明,在谷歌上查找LINQ and Or有些困难,所以我来了

我想提出以下建议:

(from creditCard in AvailableCreditCards 
where creditCard.BillToName.ToLowerInvariant().Contains(txtFilter.Text.ToLowerInvariant())
**or creditCard.CardNumber.().Contains(txtFilter.Text)**
orderby creditCard.BillToName
select creditCard)
可以使用.Where()函数来完成此操作

var cards = AvailableCreditCards.Where(card=> card.CardNumber.Contains(txtFilter.Text) || card.BillToName.ToLowerInvariant().Contains(txtFilter.Text.ToLowerInvariant());
支持LINQ的C#关键字仍然是C#。考虑<代码>其中作为条件,如<代码> < < /代码>;以相同的方式执行逻辑操作。在本例中,逻辑OR使用
|

(from creditCard in AvailableCreditCards 
 where creditCard.BillToName.ToLowerInvariant().Contains(
             txtFilter.Text.ToLowerInvariant())  
 || creditCard.CardNumber.().Contains(txtFilter.Text) 
orderby creditCard.BillToName 
select creditCard)

您应该使用在您的语言中起作用的布尔运算符。C区管道工程#

这是单曲| 这是双管上的||

处理双管的方法是它短路(如果左表达式为true,则不运行右表达式)。许多人只是使用双管,因为他们从来没有学过单管

Double-pipe的短路行为会创建分支代码,如果在右侧运行表达式会产生副作用,这可能会非常糟糕


我喜欢linq查询中使用单管道的原因是——如果有一天在linq to sql中使用查询,那么c#或运算符的底层转换都是到sql的或,其操作方式与单管道类似。

这将是两个管道,拜托。我相信一个管道是位运算符,两个管道是逻辑or运算符。我不知道!非常有趣!