提交 b6d096d3 编写于 作者: F feilong

增加C#第4题

上级 9c52ad48
{
"type": "code_options",
"author": "huanhuilong",
"source": "Format.md"
}
\ No newline at end of file
# 字符串格式化
C# 提供了丰富的字符串格式化支持。
* 普通字符串可以使用`\`来做转义
* 支持插入 Unicode 编码
* 使用 `@"23六jlqkjr"` 风格可以实现逐字文本输出
* 使用 `$"{variable_name}"` 风格可以在字符串内插入变量
以下格式化代码,能正确运行的有哪些?
一:
```csharp
Console.WriteLine("{\"err\":\"success\", \"value\":\"C#之父: 安德斯·海尔斯伯格\"}");
Console.WriteLine("{\"err\":\"success\", \"value\":\"C:\\data\"}");
```
二:
```csharp
Console.WriteLine("{\"err\":\"success\", \"value\":\"\u0043\u0023\u4e4b\u7236\u003a\u0020\u5b89\u5fb7\u65af\u00b7\u6d77\u5c14\u65af\u4f2f\u683c\"}");
```
三:
```csharp
Console.WriteLine(@"
{
""err"": ""success"",
""value"": ""C#之父: 安德斯·海尔斯伯格""
}
");
```
四:
```csharp
var msg = "success";
var value = "C#之父: 安德斯·海尔斯伯格";
Console.WriteLine($"{{\"err\":\"{msg}\", \"value\":\"{value}\"}}");
```
五:
```csharp
var msg = "success";
var value = "C#之父: 安德斯·海尔斯伯格";
Console.WriteLine($@"
{{
""err"": ""{msg}"",
""value"": ""{value}""
}}
");
```
六:
```csharp
var msg = "success";
var value = "C#之父: 安德斯·海尔斯伯格";
Console.WriteLine($@"
{
"err": "{msg}",
"value": "{value}"
}
");
```
七:
```csharp
var msg = "";
var value = "";
Console.WriteLine(@"
{
"err": "success",
"value": "C#之父: 安德斯·海尔斯伯格"
}
");
```
## 答案
```bash
一、二、三、四、五
```
### 选项
### A
```bash
一、二、三、四、六
```
### B
```bash
一、二、三、五、六
```
### C
```bash
二、三、四、五、七
```
### D
```bash
一、三、四、五、七
```
...@@ -2,5 +2,7 @@ ...@@ -2,5 +2,7 @@
"node_id": "csharp-6213732b191f434fb809de14eadee919", "node_id": "csharp-6213732b191f434fb809de14eadee919",
"keywords": [], "keywords": [],
"children": [], "children": [],
"export": [] "export": [
"Format.json"
]
} }
\ No newline at end of file
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
Console.WriteLine("{\"err\":\"success\", \"value\":\"C#之父: 安德斯·海尔斯伯格\"}");
Console.WriteLine("{\"err\":\"success\", \"value\":\"C:\\data\"}");
Console.WriteLine("{\"err\":\"success\", \"value\":\"\u0043\u0023\u4e4b\u7236\u003a\u0020\u5b89\u5fb7\u65af\u00b7\u6d77\u5c14\u65af\u4f2f\u683c\"}");
Console.WriteLine(@"
{
""err"": ""success"",
""value"": ""C#之父: 安德斯·海尔斯伯格""
}
");
var msg = "success";
var value = "C#之父: 安德斯·海尔斯伯格";
Console.WriteLine($"{{\"err\":\"{msg}\", \"value\":\"{value}\"}}");
Console.WriteLine($@"
{{
""err"": ""{msg}"",
""value"": ""{value}""
}}
");
Console.WriteLine($@"
{{
""err"": ""{msg}"",
""value"": ""{value}""
}}
");
\ No newline at end of file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册