Any – It checks whether at least one element in a collection satisfy a specified condition. It returns true if at least one element satisfy the condition else returns false if they do not.
All – It checks whether all the elements in a collection satisfy a specified condition. It returns true if all the elements satisfy the condition else returns false if they do not.
string[] names = { "Rohan", "Raj", "Rahul", "Rajesh", "Rita" }; bool IsFirstLetterR = names.All(name = > name.StartsWith("R")); //return true string[] skills = { "C", "C++", "C#", "ASP.NET", "LINQ" }; bool IsFirstLetterC = skills.Any(s = > s.StartsWith("C")); //return true string[] hobbies = { "Swimming", "Cricket", "Singing", "Watching Moview" }; bool IsHobby = hobbies.Contains("Swimming"); //return true
Contains – It checks for an element match in a collection. It returns true if match found else returns false if no match found.