Introducing Radical.sh

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

Passing array as OUT parameter in C#

Example:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace ForgetCode
  7. {
  8. class TestOut
  9. {
  10. static public void FillArray(out int[] myArray)
  11. {
  12. // Initialize the array:
  13. myArray = new int[5] { 1, 2, 3, 4, 5 };
  14. }
  15.  
  16. static public void Main()
  17. {
  18. int[] myArray; // Initialization is not required
  19.  
  20. // Pass the array using out:
  21. FillArray(out myArray);
  22.  
  23. // Display the array elements:
  24. Console.WriteLine("Array elements are:");
  25. for (int i = 0; i < myArray.Length; i++)
  26. Console.WriteLine(myArray[i]);
  27. }
  28. }
  29. }


Output:
  1. Array elements are:
  2. 1
  3. 2
  4. 3
  5. 4
  6. 5