开发者

Use Contains() extension method on arrays in C#

开发者 https://www.devze.com 2022-12-15 04:05 出处:网络
There is a Contains() extension method on IEnumerable; In VB开发者_开发知识库 I am able to do this:

There is a Contains() extension method on IEnumerable; In VB开发者_开发知识库 I am able to do this:

If New String() {"A", "B"}.Contains("B") Then
    ' ...
End If

What would be the equivalent of this in C#?


It is the same idea in C#, using LINQ extension methods:

using System.Linq;
...

if (new string[] {"A", "B"}.Contains("B")) {
    ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号