Tuesday 15 April 2014

C# pass element of value type array by reference -


I want to pass an element of an array from the reference (value type element in array, not ref type).

Is this possible? Thank you

Yes, this is absolutely possible, just like you pass any other variable from context Do:

  using the system; Class test {static zero main (string [] args) {int [] value = new int [10]; Fu (referee value [0]); Console.WriteLine (value [0]); // 10} static void foo (ref int x) {x = 10; }}  

This works because arrays are considered "collections of variables", hence the value [0] is classified as a variable Is - you will not be able to list & lt; Int & gt; Do, where the list [0] will be classified as value .


No comments:

Post a Comment