Demonstrate Predicate delegate : Array Exist Find : Data Structure C# Examples


C# Examples » Data Structure » Array Exist Find »

 

Demonstrate Predicate delegate









    
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);  
        }  
    }            
}
    
   
  
   



Output

Contents of nums: 1 4 -1 5 -9
nums contains a negative value.
First negative value is : 4


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Data Structure
» Array Exist Find