LINQ Any() Method (C#.net):
The following code shows you how to check any value in your array for some specific operation. For example, array contains {2,1,5,7,8} and you apply LINQ Any() method and queries that any of element in that array is divided by 2. Then if you see there are 2 and 8 which is divided by two so query returns True else if not true then returns false. See the code below where it is checked every element remainder equals zero.
Code
int[] number = { 6, 8, 9, 5, 7 };
bool result = number.Any(x => x % 2 == 0);
Console.Write(result);
True (Because if we take 6 and 8 mod with 2, the answer is zero )
Another Example:
List<string> words = new List<string> { "osama","saad","shizzi","bilal","ahsan" };
var res = words.Any(item => item.StartsWith("h"));
Console.Write(res);
False (Because no string is starting with letter 'h')
Related Articles:
LINQ Max() Method (C#.net)
LINQ Min() Method (C#.net)
LINQ Contains() Method (C#.net)
LINQ Zip() Method (C#.net)
LINQ Select() Method (C#.net)
LINQ SkipWhile() Method (C#.net)
LINQ TakeWhile() Method (C#.net)
LINQ Distinct() Method (C#.net)
LINQ Concat() Method (C#.net)
LINQ Min() Method (C#.net)
LINQ Contains() Method (C#.net)
LINQ Zip() Method (C#.net)
LINQ Select() Method (C#.net)
LINQ SkipWhile() Method (C#.net)
LINQ TakeWhile() Method (C#.net)
LINQ Distinct() Method (C#.net)
LINQ Concat() Method (C#.net)
0 comments:
Post a Comment