Skip to content
On this page

练习

在 .NET 编辑器中编写代码以显示一条消息

bash
Hello, Bob! You have 3 messages in your inbox. The temperature is 34.4 celsius.

存储变量输出中的以下值:

  • Bob
  • 3
  • 34.4

应为这些变量指定反映其用途的名称。

请确保根据要保存的数据类型为每个变量选择正确的数据类型。

最后,将变量和传递到一系列 Console.Write() 命令中的文本字符串合并,以形成完整的消息。

csharp
String name = "Bob";
int num = 3;
double temperature = 34.4;

Console.Write("Hello, "  + name + "! You have " + num + " messages in your inbox. The temperature is " + temperature + " celsius.");

// Hello, Bob! You have 3 messages in your inbox. The temperature is 34.4 celsius.
  • 类型为 string 的变量(用于保存名称 "Bob" )。
  • 类型为 int 的变量(用于存储消息数)。
  • 类型为 decimal 的变量(用于存储温度)。