An Action triggered by Array.ForEach : Array ForEach « Data Structure « C# / CSharp Tutorial






using System;    
   
class MyClass { 
  public int i;  
   
  public MyClass(int x) { 
    i = x; 
  }
}
  
class MainClass {       
 
  static void show(MyClass o) { 
    Console.Write(o.i + " "); 
  } 
 
  public static void Main() {       
    MyClass[] nums = new MyClass[5];  
  
    nums[0] = new MyClass(5);  
    nums[1] = new MyClass(2);  
    nums[2] = new MyClass(3);  
    nums[3] = new MyClass(4);  
    nums[4] = new MyClass(1);  
     
    Console.Write("Contents of nums: ");   
 
    // Use action to show the values. 
    Array.ForEach(nums, MainClass.show); 
 
    Console.WriteLine();   
 
  }       
}
Contents of nums: 5 2 3 4 1








11.15.Array ForEach
11.15.1.Array.ForEach with a delegate
11.15.2.An Action triggered by Array.ForEach
11.15.3.Use an Action to change the values
11.15.4.foreach with Arrays
11.15.5.Foreach and string index