Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Passing array as a parameter in C#

  1. public class ArrayClass
  2. {
  3. static void PrintArray(int[,] w)
  4. {
  5. // Display the array elements:
  6. for (int i=0; i < 4; i++)
  7. for (int j=0; j < 2; j++)
  8. Console.WriteLine("Element({0},{1})={2}", i, j, w[i,j]);
  9. }
  10.  
  11. public static void Main()
  12. {
  13. // Pass the array as a parameter:
  14. PrintArray(new int[,] {{1,2}, {3,4}, {5,6}, {7,8}});
  15. }
  16. }


Output:
  1. Element(0,0)=1
  2. Element(0,1)=2
  3. Element(1,0)=3
  4. Element(1,1)=4
  5. Element(2,0)=5
  6. Element(2,1)=6
  7. Element(3,0)=7
  8. Element(3,1)=8