C# Collection Contains
Description
determines whether an element is in the Collection.
Syntax
public bool Contains(
T item
)
Parameters
item
- The object to locate in the Collection. The value can be null for reference types.
Returns
Collection.Contains
method returns true if item is found in the Collection; otherwise, false.
Example
// w w w. java 2 s . c o m
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
public class Demo
{
public static void Main()
{
Collection<string> myData = new Collection<string>();
myData.Add("A");
myData.Add("B");
myData.Add("C");
myData.Add("D");
Console.WriteLine(myData.Contains("A"));
}
}
The code above generates the following result.