Array.Exists : Array « System « C# / C Sharp by API





Array.Exists

 


using System;   
  
class MainClass {      
 
  static bool isCriteria(int v) { 
    if(v > 1) 
      return true; 
    return false; 
  } 
 
  public static void Main() {      
    int[] nums = { 1, 4, -1, 5, -9 }; 
    
    Console.Write("Contents of nums: ");  
    foreach(int i in nums)   
      Console.Write(i + " ");  
    Console.WriteLine();  
  
    if(Array.Exists(nums, isCriteria)) { 
      Console.WriteLine("nums contains a negative value."); 
 
      // Now, find first negative value. 
      int x = Array.Find(nums, isCriteria); 
      Console.WriteLine("First negative value is : " + x); 
    } 
  }      
}

   
  










Related examples in the same category

1.Array.AsReadOnly
2.Array.BinarySearch
3.Array.Clone
4.Array.ConvertAll
5.Array.Copy
6.Array.CopyTo
7.Array.Count
8.Array.CreateInstance
9.Array.Find
10.Array.FindAll
11.Array.ForEach
12.Array.GetEnumerator()
13.Array.GetLength()
14.Array.GetLowerbound
15.Array.GetUpperBound
16.Array.IndexOf
17.Array.LastIndexOf
18.Array.Length
19.Array.Rank
20.Array.Resize
21.Array.Reverse
22.Array.Reverse(nums, 1, 3)
23.Array.Sort
24.Array.Sort(names, Comparer.DefaultInvariant)
25.Array.SyncRoot