Ref Local Arrays - CSharp Language Basics

CSharp examples for Language Basics:ref

Description

Ref Local Arrays

Demo Code

using System.ComponentModel;
class RefLocalArrays
{
   static void Main()
   {/*from  w  ww .  j  ava  2 s .  c o  m*/
      var array = new (int x, int y)[10];
      for (int i = 0; i < array.Length; i++)
      {
         array[i] = (i, i);
      }
      for (int i = 0; i < array.Length; i++)
      {
         ref var element = ref array[i];
         element.x++;
         element.y *= 2;
      }
   }
}

Related Tutorials