Contains

The Contains method is used to identify if an item exists in a collection.

Basic example

In the code example below, we have an array of strings - color names.

By using the .Contains method, we can verify if blue is contained within the array of strings.

Live example: https://dotnetfiddle.net/LTfxkc

// Example array of colors
var colors = new[] { "red", "blue", "green", "yellow", "purple", "orange" };

// Check if array contains 'blue'
bool result = colors.Contains("blue");

Console.WriteLine(result);

// output: True