C# Contains

Check whether a value is in an array.

int[] arr = new int[] { 3, 4, 2, 1, 5, 8 };
int ky = 5;
int flag = 0;
foreach (int i in arr)
{
if (i == ky) {flag = 1; break;}
}

Check whether an ArrayList contains a value or not.
ArrayList al = new ArrayList();
al.Add("Monday");
al.Add("Tuesday");
al.Add("Wednesday");
al.Contains("Monday");

Check whether a List contains a value or not.
using System.Collections.Generic;
List lst = new List { 4, 9, 18, 3 };
lst.Contains(18);

Check whether a Dictionary contains a key or value.
using System.Collections.Generic;
Dictionary d = new Dictionary {
{"Jacobs",28},{"Mary",26}
};
d.ContainsKey("Jacobs");
d.ContainsValue(28);



endmemo.com © 2024  | Terms of Use | Privacy | Home