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.
Dim number() As Integer = {6, 8, 9, 5, 7}
Dim result As Boolean = number.Any(Function(x As Integer) x Mod 2 = 0)
Console.WriteLine(result)
Output of the program is:
True (Because if we take 6 and 8 mod with 2 the answer is zero )
Another Example:
' Creating a list of Integers.
Dim numbers As New List(Of Integer)(New Integer() {1, 19, 35, 7, 2})
Dim result As Boolean = numbers.Any(Function(x As Integer) x / 2 = 0)
Console.WriteLine(result)
Output of the program is:
False (Because if we divide any element with 2 the answer is not zero )
0 comments:
Post a Comment