Passing Parameters By Value and By Ref : Parameters Passing : Language Basics C# Source Code


Custom Search

C# Source Code » Language Basics » Parameters Passing »

 

Passing Parameters By Value and By Ref









    

/*
 * C# Programmers Pocket Consultant
 * Author: Gregory S. MacBeth
 * Email: gmacbeth@comporium.net
 * Create Date: June 27, 2003
 * Last Modified Date:
 */
using System;

namespace Client.Chapter_5___Building_Your_Own_Classes
{
  public class PassingParametersByValueandByRef
  {
    static void Main(string[] args)
    {
      int MyInt = 5;

      MyIntArray = new int[10];
      ObjectCount++;
      Method2();
      Method2(1, 2);
      MyMethodRef(ref MyInt);
      Method2(new int[] { 1, 2, 3, 4 });
    }
    static private int MyInt = 5;
    static public int MyInt2 = 10;
    static public int[] MyIntArray;
    private static int ObjectCount = 0;
    static public int MyMethodRef(ref int myInt)
    {
      MyInt = MyInt + myInt;
      return MyInt;
    }
    static public int MyMethod(int myInt)
    {
      MyInt = MyInt + myInt;
      return MyInt;
    }
    static private long MyLongMethod(ref int myInt)
    {
      return myInt;
    }
    static public void Method2(params int[] args)
    {
      for (int I = 0; I < args.Length; I++)
        Console.WriteLine(args[I]);
    }
  }
}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Language Basics
» Parameters Passing