我正在尝试在 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/