C# Array.Contains() 编译错误

标签 c# .net linq

我正在尝试在 C# 中使用 Array.Contains () 方法,但由于某种原因它无法编译,尽管我相信我使用的是 C# 4.0,而 C# 应该在 3.0 及更高版本中支持它。

if (! args.Contains ("-m"))
    Console.WriteLine ("You must provide a message for this commit.");

我得到这个错误:

Main.cs(42,15): error CS1061: 'System.Array' does not contain a definition for 'Contains' and no extension method 'Contains' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

我从命令行编译,没有选项:“csc Main.exe”。

最佳答案

您需要在程序开头添加using System.Linq;

关于C# Array.Contains() 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5838322/

相关文章:

c# - 播放视频黑色矩形

c# - 如何使用NEST为Elasticsearch指定索引?

c# - 信号量会阻止指令重新排序吗?

c# - WebAPI One Asp.Net (ASP5/vNext) 中的分页

c# - 在 LINQ to Entities 中使用中间实体会导致 System.NotSupportedException

c# - WPF 保存网页浏览器 HTML

c# - 更新操作缓存并保持不同步

c# - 将 Web 上下文传递给 ASP MVC 应用程序中的 'service'

c# - 如何使用 jQuery 设置列表框的值?

c# - 如何使用linq进行过滤和求和