Mark Reference parameter variables - CSharp Custom Type

CSharp examples for Custom Type:Method Parameter

Description

Mark Reference parameter variables

Demo Code

using System;/*  w ww  .  j  av a  2  s  . c  o  m*/
class nbr
{
   public double square( ref double x )
   {
      x = x * x;
      return x;
   }
}
class TestApp
{
   public static void Main()
   {
      nbr doit = new nbr();
      double nbr1 = 3;
      double retVal = 0;
      Console.WriteLine("Before square -> nbr1 = {0}, retVal = {1}", nbr1, retVal);
      retVal = doit.square( ref nbr1 );
      Console.WriteLine("After square -> nbr1 = {0}, retVal = {1}", nbr1, retVal);
   }
}

Result


Related Tutorials