为什么不使用c#在控制台上显示变量的输出

Nik*_*rma 2 c#

/**
Write a program in C# language to perform the following operation:

b. Finding greatest of n numbers

**/
using System;
using System.Linq;


class Greatest
{
    public static void Main(String[] args)
    {   
        //get the number of elements
        Console.WriteLine("Enter the number of elements");
        int n;
        n=Convert.ToInt32(Console.ReadLine());
        int[] array1 = new int[n];         
        //accept the elements
        for(int i=0; i<n; i++)
        {
            Console.WriteLine("Enter element no:",i+1);
            array1[i]=Convert.ToInt32(Console.ReadLine());
        }
        //Greatest
        int max=array1.Max();
        Console.WriteLine("The max is ", max);

        Console.Read();
    }
}
Run Code Online (Sandbox Code Playgroud)

该程序不输出变量的值,我无法弄清楚为什么?

样本输出是

 Enter the number of elements
3
Enter element no:
2
Enter element no:
3
Enter element no:
2
The max is 
Run Code Online (Sandbox Code Playgroud)

注意没有变量的输出.

谢谢

Geo*_*ton 13

你错过了你的格式项目,例如

更改...

Console.WriteLine("The max is ", max);
Run Code Online (Sandbox Code Playgroud)

至...

Console.WriteLine("The max is {0}", max);
Run Code Online (Sandbox Code Playgroud)

  • 或者`Console.WriteLine("最大值是"+最大值);` (3认同)