Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Array.Contains () compilation error

Tags:

c#

.net

linq

I'm trying to use the Array.Contains () method in C#, and for some reason it's failing to compile, eve though I believe that I'm using C# 4.0, and C# should support this in 3.0 and later.

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

And I get this error:

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

I am compiling from the command line, with no options: "csc Main.exe".

like image 831
Ashton K Avatar asked Apr 29 '11 23:04

Ashton K


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C language?

C is an imperative procedural language supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support.


2 Answers

You need to add using System.Linq; at the beginning of your program.

like image 85
Blindy Avatar answered Sep 20 '22 09:09

Blindy


Did you forget using System.Linq?

By the way, if you can't use LINQ there are many other options such as Array.Exists.

like image 29
Jon Avatar answered Sep 20 '22 09:09

Jon