提交 9c52ad48 编写于 作者: F feilong

增加C#第3题

上级 e6053a7a
{
"type": "code_options",
"author": "huanhuilong",
"source": "Variable.md"
}
\ No newline at end of file
# 隐式变量的类型
C# 允许使用关键字`var`隐式声明变量的类型。例如下面两个语句等价:
```csharp
string user = "machine";
var user = "machine";
```
以下代码中的四个`var`声明的变量,对应的C#类型分别是什么?
```csharp
var e = 'c';
var f = 10;
var g = 10.2m;
var h = true;
```
## 答案
```csharp
char e = 'c';
int f = 10;
decimal g = 10.2m;
bool h = false;
```
## 选项
### A
```csharp
string e = 'c';
int f = 10;
decimal g = 10.2m;
bool h = false;
```
### B
```csharp
char e = 'c';
int f = 10;
float g = 10.2m;
bool h = false;
```
### C
```csharp
char e = 'c';
int f = 10;
decimal g = 10.2m;
boolean h = false;
```
......@@ -3,6 +3,7 @@
"keywords": [],
"children": [],
"export": [
"String.json"
"String.json",
"Variable.json"
]
}
\ No newline at end of file
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
// Console.WriteLine("Hello, World!");
string helloworld1 = "Hello, World!";
Console.WriteLine(helloworld1);
// string helloworld1 = "Hello, World!";
// Console.WriteLine(helloworld1);
String helloworld2 = "Hello, World!";
Console.WriteLine(helloworld2);
// String helloworld2 = "Hello, World!";
// Console.WriteLine(helloworld2);
var helloworld3 = "Hello, World!";
Console.WriteLine(helloworld3);
// var helloworld3 = "Hello, World!";
// Console.WriteLine(helloworld3);
string $helloworld4 = "Hello, World!";
Console.WriteLine($helloworld3);
// string $helloworld4 = "Hello, World!";
// Console.WriteLine($helloworld3);
string helloworld5 = 'Hello, World!';
Console.WriteLine($helloworld5);
// string helloworld5 = 'Hello, World!';
// Console.WriteLine($helloworld5);
var helloworld6;
helloworld6 = "Hello, World!";
Console.WriteLine(helloworld6);
\ No newline at end of file
// var helloworld6;
// helloworld6 = "Hello, World!";
// Console.WriteLine(helloworld6);
char a = 'c';
int b = 10;
decimal c = 10.2m;
bool d = false;
var e = 'c';
var f = 10;
var g = 10.2m;
var h = true;
float g = 10.2m;
// Console.WriteLine(a);
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册