An array variable can be referenced by another array variable (referringvariable). While referring, the
referring array variable refers to the values of the referenced array variable.
Example 2 demonstrates the use of array references.
referring array variable refers to the values of the referenced array variable.
Example 2 demonstrates the use of array references.
Example 2:
using System;
class StudentReferences
{
public static void Main()
{
string[] classOne = { "Allan", "Chris", "Monica" };
string[] classTwo = { "Katie", "Niel", "Mark" };
Console.WriteLine("Students of Class I:\tStudents of Class II");
for (int i = 0; i < 3; i++)
{
Console.WriteLine(classOne[i] + "\t\t\t" + classTwo[i]);
}
classTwo = classOne;
Console.WriteLine("\nStudents of Class II after referencing Class I:");
for (int i = 0; i < 3; i++)
{
Console.WriteLine(classTwo[i] + " ");
}
Console.WriteLine();
classTwo[2] = "Mike";
Console.WriteLine("Students of Class I after changing the third student in Class II:");
for (int i = 0; i < 3; i++)
{
Console.WriteLine(classOne[i] + " ");
}
}
}
class StudentReferences
{
public static void Main()
{
string[] classOne = { "Allan", "Chris", "Monica" };
string[] classTwo = { "Katie", "Niel", "Mark" };
Console.WriteLine("Students of Class I:\tStudents of Class II");
for (int i = 0; i < 3; i++)
{
Console.WriteLine(classOne[i] + "\t\t\t" + classTwo[i]);
}
classTwo = classOne;
Console.WriteLine("\nStudents of Class II after referencing Class I:");
for (int i = 0; i < 3; i++)
{
Console.WriteLine(classTwo[i] + " ");
}
Console.WriteLine();
classTwo[2] = "Mike";
Console.WriteLine("Students of Class I after changing the third student in Class II:");
for (int i = 0; i < 3; i++)
{
Console.WriteLine(classOne[i] + " ");
}
}
}