1. Exists is not the linq standard; Exist is there from 2.0;
2. Just as IndexOf, Contains search strings. It checks if one of the substring is contained in another.
3. Exists returns whether any of the List elements found. You can use a loop and if-statement also;
4. The difference is only Contains support by Linq parametrs to Entities, Exists does not supported
5. How to use Exists in c#
class Program
{
static void Main(string[] args)
{
List<int> list = new List<int> { 1, 2, 3, 4 };
// See if any elements equal to 3
bool exists = list.Exists(element => element == 3); // True
Console.WriteLine(exists);
// Check for numbers eqal to 5
exists = list.Exists(element => element == 5); // False
Console.WriteLine(exists);
}
}
6. How to Use Contain in c#
class Program
{
static void Main(string[] args)
{
string s1 = "Check for the contains method in C#";
string s2 = "contains"; // Contains is case sensetive
bool bln;
bln = s1.Contains(s2);
Console.WriteLine("string, s2, in string, s1?: {0}", bln); //bln =true
}
}
No comments:
Post a Comment