• Top Posts

    Passing the 1-D array arr to the method Result

    •  In the below program, we are passing the 1-D array arr to the method Result. The method is static and it will print the array elements which are passed to it.




      class ArrayAsArgument  
       {  
         static void Result(int[] arr)  
         {  
           // displaying the array elements   
           for (int i = 0; i < arr.Length; i++)  
           {  
             Console.WriteLine("Array Element: " + arr[i]);  
           }  
         }  
         // Main method   
         public static void Main()  
         {  
           // declaring an array   
           // and intializing it   
           int[] arr = { 1, 2, 3, 4, 5 };  
           // callling the method   
           Result(arr);  
           Console.ReadLine();  
         }  
       } 
    

    No comments

    Post Top Ad

    ad728

    Post Bottom Ad

    ad728