当我{0}
在以下代码中使用时:
class Program
{
double width;
double height;
public void getData() {
Console.WriteLine("Enter Width:");
width = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter Height:");
height = Convert.ToDouble(Console.ReadLine());
}
public double calcArea() {
return width * height;
}
public void display() {
Console.WriteLine("Area is : {0}",calcArea());
}
}
class Area
{
static void Main(string[] args)
{
Program p = new Program();
p.getData();
p.display();
}
}
输出是:
输入宽度:
6
输入高度:
9
面积:54
当我在此使用 {0} 时:
class NewArea
{
static void Main(String[] args) {
double width;
double height;
double area;
Console.WriteLine("Enter Width: ");
width = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter Height: ");
height = Convert.ToDouble(Console.ReadLine());
area = width * height;
Console.WriteLine("Area is: {0}" +area);
}
}
输出是
输入宽度:
4
输入高度:
5
面积:{0}20
是什么{0}
意思?