By 22/07/2015 1 Comments

Array Reference In C#

  • When you assign one array variable to another array variable it is called array reference.
  •  It means these two variables will refer to that same array. Remember neither copy of an array will be created, nor its data or contents will be copied.


using System;
namespace csharpBasic
    class Program
        static void Main(string[] args)
            // A string array declaration.
            string[] originalArray = new string[2];

            // An orignalArray is being assigned to referenceArray.
            string[] referenceArray = originalArray;

            // Values are assigned to an originalArray.
            originalArray[0] = "C#";
            originalArray[1] = "";

            // Values are assigned to a referenceArray.
            referenceArray[0] = "Html 5";
            referenceArray[1] = "Javascript";

            Console.WriteLine("Original Array: ");

            // Loop through each originalArray values.
            foreach (string displayElementsOrg in originalArray)
                Console.WriteLine("\t {0}", displayElementsOrg);

            Console.WriteLine("Referenced Array: ");

            // Loop through each referenceArray values.
            foreach (string displayElementsRef in referenceArray)
                Console.WriteLine("\t {0}", displayElementsRef);

        The Output will be:
        Original Array:
                 Html 5
        Referenced Array:
                 Html 5

← Previous Tutorial

Posted in: C# Basics, C#.NET

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .