"
那么下面的运算结果是什么?
using System;
using System.Collections;
public class MyClass
{
public static void Main()
{
Console.WriteLine("Test1的结果是:");
Test1();
Console.WriteLine("Test2的结果是:");
Test2();
}
public static void Test1()
{
Sample [] sample = new Sample[3];
for (int i=0;i<3;i++)
{
sample[i] = new Sample();
sample[i].Name = i.ToString();
}
Sample [] tempSample = new Sample[3];
for (int i=0;i<3;i++)
{
tempSample[i] = sample[i];
}
sample[0] = tempSample[1];
sample[1] = tempSample[2];
sample[2] = tempSample[0];
for (int i=0;i<3;i++)
{
Console.WriteLine(sample[i].Name);
}
}
public static void Test2()
{
Sample sample0 = new Sample();
Sample sample1 = new Sample();
Sample sample2 = new Sample();
sample0.Name = "0";
sample1.Name = "1";
sample2.Name = "2";
Sample tempSample0 = sample0;
Sample tempSample1 = sample1;
Sample tempSample2 = sample2;
sample0 = tempSample1;
sample1 = tempSample2;
sample2 = tempSample0;
Console.WriteLine(sample0.Name);
Console.WriteLine(sample1.Name);
Console.WriteLine(sample2.Name);
RL();
}
private static void WL(string text, params object[] args)
{
Console.WriteLine(text, args);
}
private static void RL()
{
Console.ReadLine();
}
private static void Break()
{
System.Diagnostics.Debugger.Break();
}
}
public class Sample
{
public string Name;
}
using System.Collections;
public class MyClass
{
public static void Main()
{
Console.WriteLine("Test1的结果是:");
Test1();
Console.WriteLine("Test2的结果是:");
Test2();
}
public static void Test1()
{
Sample [] sample = new Sample[3];
for (int i=0;i<3;i++)
{
sample[i] = new Sample();
sample[i].Name = i.ToString();
}
Sample [] tempSample = new Sample[3];
for (int i=0;i<3;i++)
{
tempSample[i] = sample[i];
}
sample[0] = tempSample[1];
sample[1] = tempSample[2];
sample[2] = tempSample[0];
for (int i=0;i<3;i++)
{
Console.WriteLine(sample[i].Name);
}
}
public static void Test2()
{
Sample sample0 = new Sample();
Sample sample1 = new Sample();
Sample sample2 = new Sample();
sample0.Name = "0";
sample1.Name = "1";
sample2.Name = "2";
Sample tempSample0 = sample0;
Sample tempSample1 = sample1;
Sample tempSample2 = sample2;
sample0 = tempSample1;
sample1 = tempSample2;
sample2 = tempSample0;
Console.WriteLine(sample0.Name);
Console.WriteLine(sample1.Name);
Console.WriteLine(sample2.Name);
RL();
}
private static void WL(string text, params object[] args)
{
Console.WriteLine(text, args);
}
private static void RL()
{
Console.ReadLine();
}
private static void Break()
{
System.Diagnostics.Debugger.Break();
}
}
public class Sample
{
public string Name;
}
"
路人丙兄在下面的回复里,指出了问题所在,结果我还误认为是录错了代码。再经楼下兄弟指出,于是用SC看了一下,呵呵,原来是我闹了个大笑话,不好意思了各位