From 9c52ad4837c91b4e22c553cc3683e44f7b3d4ba6 Mon Sep 17 00:00:00 2001 From: feilong Date: Wed, 15 Dec 2021 16:15:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0C#=E7=AC=AC3=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Variable.json" | 5 ++ .../Variable.md" | 55 +++++++++++++++++++ .../config.json" | 3 +- .../sample/Program.cs" | 41 +++++++++----- 4 files changed, 89 insertions(+), 15 deletions(-) diff --git "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/2.C#\346\226\207\346\234\254\345\200\274\345\222\214\345\217\230\351\207\217/Variable.json" "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/2.C#\346\226\207\346\234\254\345\200\274\345\222\214\345\217\230\351\207\217/Variable.json" index e69de29..0bbd560 100644 --- "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/2.C#\346\226\207\346\234\254\345\200\274\345\222\214\345\217\230\351\207\217/Variable.json" +++ "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/2.C#\346\226\207\346\234\254\345\200\274\345\222\214\345\217\230\351\207\217/Variable.json" @@ -0,0 +1,5 @@ +{ + "type": "code_options", + "author": "huanhuilong", + "source": "Variable.md" +} \ No newline at end of file diff --git "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/2.C#\346\226\207\346\234\254\345\200\274\345\222\214\345\217\230\351\207\217/Variable.md" "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/2.C#\346\226\207\346\234\254\345\200\274\345\222\214\345\217\230\351\207\217/Variable.md" index e69de29..79dfbac 100644 --- "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/2.C#\346\226\207\346\234\254\345\200\274\345\222\214\345\217\230\351\207\217/Variable.md" +++ "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/2.C#\346\226\207\346\234\254\345\200\274\345\222\214\345\217\230\351\207\217/Variable.md" @@ -0,0 +1,55 @@ +# 隐式变量的类型 + +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; +``` diff --git "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/2.C#\346\226\207\346\234\254\345\200\274\345\222\214\345\217\230\351\207\217/config.json" "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/2.C#\346\226\207\346\234\254\345\200\274\345\222\214\345\217\230\351\207\217/config.json" index 5f1936a..4cf5c7b 100644 --- "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/2.C#\346\226\207\346\234\254\345\200\274\345\222\214\345\217\230\351\207\217/config.json" +++ "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/2.C#\346\226\207\346\234\254\345\200\274\345\222\214\345\217\230\351\207\217/config.json" @@ -3,6 +3,7 @@ "keywords": [], "children": [], "export": [ - "String.json" + "String.json", + "Variable.json" ] } \ No newline at end of file diff --git "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/2.C#\346\226\207\346\234\254\345\200\274\345\222\214\345\217\230\351\207\217/sample/Program.cs" "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/2.C#\346\226\207\346\234\254\345\200\274\345\222\214\345\217\230\351\207\217/sample/Program.cs" index d62d0c1..0716dd0 100644 --- "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/2.C#\346\226\207\346\234\254\345\200\274\345\222\214\345\217\230\351\207\217/sample/Program.cs" +++ "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/2.C#\346\226\207\346\234\254\345\200\274\345\222\214\345\217\230\351\207\217/sample/Program.cs" @@ -1,22 +1,35 @@ // 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 -- GitLab