我正在尝试创建一个程序,其中包含一个反转四个变量位置的方法。编写一个Main()方法,演示该方法是否正常工作。我怎么做这个我是C#的新手。
答案 0 :(得分:0)
我认为OP正在寻找这个
static void Main(string[] args)
{
int first = 111;
int second = 222;
int third = 333;
int fourth = 444;
Console.WriteLine("Numbers in normal order: {0},{1},{2},{3}", first, second, third, fourth);
Reverse(ref first, ref second, ref third, ref fourth);
Console.WriteLine("Numbers in inverse order: {0},{1},{2},{3}", first, second, third, fourth);
Console.WriteLine("Press Enter To Exit");
Console.ReadLine();
}
public static void Reverse(ref int first1, ref int second2, ref int third3, ref int fourth4)
{
int temp, temp1;
temp = first1;
first1 = fourth4;
temp1 = second2;
second2 = third3;
third3 = temp1;
fourth4 = temp;
}