C#WriteLine方法显示括号内的数字,而不是我希望用的数字

C#WriteLine方法显示括号内的数字,而不是我希望用的数字,c#,templates,console.writeline,C#,Templates,Console.writeline,我刚开始学习C#,这是我的简单家庭作业程序代码: using System; namespace Concatenate_Data { class Program { static void Main(string[] args) { string firstName = Console.ReadLine(); string lastName = Console.ReadLine();

我刚开始学习C#,这是我的简单家庭作业程序代码:

using System;

namespace Concatenate_Data
{
    class Program
    {
        static void Main(string[] args)
        {
            string firstName = Console.ReadLine();
            string lastName = Console.ReadLine();
            int age = int.Parse(Console.ReadLine());
            string town = Console.ReadLine();

            Console.WriteLine($"You are {0} {1}, a {2}-years old person from {3}.", firstName, lastName, age, town);
        }
    }
}

它没有输出例如“You is Peter Johnson,一个来自Sofia的20岁的人”,而是输出“You is 0 1,一个来自3的2岁的人。我如何解决这个问题?我甚至从他们给我们的示例中复制了代码1:1。

$
符号将字符串作为插值字符串。因此它不能作为
string.Format()
有效。您可以参考文档

当您按照以下步骤编写代码时,您可能会得到所需的输出:

Console.WriteLine($"You are {firstName} {lastName}, a {age}-years old person from {town}.");

删除字符串前的$字符。这表示@Christie No,
控制台。WriteLine
将为您执行
字符串。Format