嗨,我是c#编程的新手,我正在做一个活动,它将输入多少个输入,并且它将查看插入的数字。现在我只有一个问题,我如何才能仅查看最后插入的号码,这是我的代码:

     Console.Write("Enter How Many Inputs: ");
        int num1 = int.Parse(Console.ReadLine());
        int[] arr = new int[num1];
        for (int i = 0; i < num1; i++) {
            Console.Write("Input Value #" + (i + 1) + ":");
            arr[i] = int.Parse(Console.ReadLine());
        }
        Console.Write("The Numbers inserted are: ");
        for (int x = 0; x < arr.Length; x++) {
            Console.Write(" " + arr[x]);
        }
        Console.Write("The Last Number Inserted is: ");
        (???)

  Sample Output:
  Enter How Many Inputs: 3
  Value #1: 80
  Value #2: 83
  Value #3: 50
  The Numbers inserted are: 80 83 50
  The Last Number inserted is: 50


我不知道我将使用哪个循环查看最后插入的号码。谢谢!

最佳答案

arr[arr.length-1]


要么

arr[num1-1]

10-07 19:28
查看更多