Use Contains() extension method on arrays in C#

不羁岁月 提交于 2021-01-29 03:31:26

问题


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#?


回答1:


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

using System.Linq;
...

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


来源:https://stackoverflow.com/questions/1972820/use-contains-extension-method-on-arrays-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!