diff --git "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format.json" "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format1.json" similarity index 100% rename from "data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format.json" rename to "data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format1.json" diff --git "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format.md" "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format1.md" similarity index 87% rename from "data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format.md" rename to "data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format1.md" index 03741f97a10d9f21cfa48e7abfad7c15e786921d..cb604403c6fcc0660eedcfde01a8eab37a925280 100644 --- "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format.md" +++ "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format1.md" @@ -82,32 +82,22 @@ Console.WriteLine(@" ## 答案 -```bash -一、二、三、四、五 -``` +一, 二, 三, 四, 五 -### 选项 +## 选项 ### A -```bash -一、二、三、四、六 -``` +一, 二, 三, 四, 六 ### B -```bash -一、二、三、五、六 -``` +一, 二, 三, 五, 六 ### C -```bash -二、三、四、五、七 -``` +二, 三, 四, 五, 七 ### D -```bash -一、三、四、五、七 -``` +一, 三, 四, 五, 七 diff --git "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/StringFormatting.json" "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format2.json" similarity index 100% rename from "data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/StringFormatting.json" rename to "data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format2.json" diff --git "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/StringFormatting.md" "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format2.md" similarity index 58% rename from "data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/StringFormatting.md" rename to "data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format2.md" index c27e2bc229d10c3f294b9f8e120bfae4bed23b15..b2b7a6248a5d83f0f07051fad3b0239a40c9dd54 100644 --- "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/StringFormatting.md" +++ "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format2.md" @@ -1,8 +1,7 @@ -# 在C#中执行基本字符串格式设置 +# 在CSharp中执行基本字符串格式设置(1) System.String是一个类,专门用于存储字符串,允许对字符串进行许多操作。由于这种数据类 -型非常重要,C#提供了它自己的关键字和相关的语法,以便于使用这个类来轻松地处理字符串。 -String 源码网址: https://referencesource.microsoft.com/#mscorlib/system/string.cs +型非常重要,CSharp提供了它自己的关键字和相关的语法,以便于使用这个类来轻松地处理字符串。 使用运算符重载可以连接字符串: @@ -12,7 +11,7 @@ message1 += ", CSDN"; // return "Hello, CSDN" string message2 = message1 + "!"; //return "Hello, CSDN!" ``` -C#还允许使用类似于索引器的语法来提取指定的字符: +CSharp还允许使用类似于索引器的语法来提取指定的字符: ```csharp string message1 = "Hello"; @@ -37,15 +36,9 @@ char char1 = message[1] // return 'e' |ToUpper|把字符串转换为大写形式| |Trim |删除首位的空白| ->注意如果Format想要输出'{'或'}',请这样string.Format("{{Hello}}"); +注意如果Format想要输出'{'或'}',请这样string.Format("{{Hello}}"); -除了这些方法C#还提供了'@'和'$',@是可以忽略字符串的转义,$是可以把代码插到字符串中。 - -```csharp -int count = 6; -string str1 = $"6{count}6"; // return "666" -string str2 = @"6\r6\n6"; //return "6\r6\n6" -``` +除了这些方法CSharp还提供了'@'和'$',@是可以忽略字符串的转义,'$'是可以把代码插到字符串中。 以下程序中,不能使str3等于`"Hello, CSDN!"`的是: @@ -82,42 +75,3 @@ var str1 = "Hello, "; var str2 = "CSDN!"; var str3 = string.Concat(str1, str2); ``` - -|格式说明符|应用|含义|示例| -|----------|----|----|----| -|C|数字类型|特定地区的货币值|$666.00| -|D|用于数字类型|一般的整数|666| -|E|数字类型|科学计数法|6.660000E+002| -|F|数字类型|小数点后的位数固定|666.00| -|G|数字类型|一般的数字|666| -|N|数字类型|通常是特定地区的数字格式|666.00| -|P|数字类型|百分比计数法|66,600.00%| -|X|只用于整数类型|十六进制格式|29A| - -以下程序中,能让str1等于666.0的是: - -## 答案 - -```csharp -string str1 = string.Format("{0:F1}", 666); -``` - -## 选项 - -### A - -```csharp -string str1 = string.Format("{0:N}", 666); -``` - -### B - -```csharp -string str1 = string.Format("{0:C}", 666); -``` - -### C - -```csharp -string str1 = string.Format("{0:D}", 666); -``` \ 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/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format3.json" "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format3.json" new file mode 100644 index 0000000000000000000000000000000000000000..c79de841cf59a18afb9c791dea5f85b782744d60 --- /dev/null +++ "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format3.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "Gao996", + "source": "StringFormatting.md", + "notebook_enable": false, + "exercise_id": "055519a8722d41a694d846cd1bc196ba" +} \ 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/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format3.md" "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format3.md" new file mode 100644 index 0000000000000000000000000000000000000000..6eb5b0f05f95e0107dfa65bcf5a827db58da90f2 --- /dev/null +++ "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/Format3.md" @@ -0,0 +1,40 @@ +# 在CSharp中执行基本字符串格式设置(2) + +|格式说明符|应用|含义|示例| +|----------|----|----|----| +|C|数字类型|特定地区的货币值|$666.00| +|D|用于数字类型|一般的整数|666| +|E|数字类型|科学计数法|6.660000E+002| +|F|数字类型|小数点后的位数固定|666.00| +|G|数字类型|一般的数字|666| +|N|数字类型|通常是特定地区的数字格式|666.00| +|P|数字类型|百分比计数法|66,600.00%| +|X|只用于整数类型|十六进制格式|29A| + +以下程序中,能让str1等于666.0的是: + +## 答案 + +```csharp +string str1 = string.Format("{0:F1}", 666); +``` + +## 选项 + +### A + +```csharp +string str1 = string.Format("{0:N}", 666); +``` + +### B + +```csharp +string str1 = string.Format("{0:C}", 666); +``` + +### C + +```csharp +string str1 = string.Format("{0:D}", 666); +``` \ 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/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/config.json" "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/config.json" index 8c862f95e4709333ca2ed57be091d2656d2927d5..ab8b8ece4623f0ed2c0fec12cef588adc38b90a0 100644 --- "a/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/config.json" +++ "b/data/1..NET\345\210\235\351\230\266/2.C#\350\257\255\346\263\225/3.C#\345\255\227\347\254\246\344\270\262\346\240\274\345\274\217\350\256\276\347\275\256/config.json" @@ -5,8 +5,9 @@ ], "children": [], "export": [ - "Format.json", - "StringFormatting.json" + "Format1.json", + "Format2.json", + "Format3.json" ], "keywords_must": [], "keywords_forbid": [] diff --git "a/data/1..NET\345\210\235\351\230\266/3.C#\347\211\271\346\200\247/1.C#3.0\347\211\271\346\200\247/ImplicitType.md" "b/data/1..NET\345\210\235\351\230\266/3.C#\347\211\271\346\200\247/1.C#3.0\347\211\271\346\200\247/ImplicitType.md" index 4cbf609d432b4e310f9ab2b9d5c196637bb09a39..ac8d5581f730e1fdd87eb74a4cb7d556442e2693 100644 --- "a/data/1..NET\345\210\235\351\230\266/3.C#\347\211\271\346\200\247/1.C#3.0\347\211\271\346\200\247/ImplicitType.md" +++ "b/data/1..NET\345\210\235\351\230\266/3.C#\347\211\271\346\200\247/1.C#3.0\347\211\271\346\200\247/ImplicitType.md" @@ -1,16 +1,20 @@ -# C# 3.0 ʽͱر +# CSharp 3.0 特性 隐式类型本地变量 -C# 3.0 ʼڷΧıԾʽ͡varʽͱرΪǿͣûѾͣһ +从C# 3.0 开始,在方法范围内声明的变量可以具有隐式“类型”var。隐式类型本地变量为强类型,就像用户已经自行声明该类型,但编译器决定类型一样。 -```var i = Hello CSDN;```룬ѡiǣ +```csharp +var i = “Hello CSDN!”; +``` + +看这句代码,在下列选项中i的类型是: -## +## 答案 ```csharp string ``` -## ѡ +## 选项 ### A diff --git "a/data/1..NET\345\210\235\351\230\266/3.C#\347\211\271\346\200\247/1.C#3.0\347\211\271\346\200\247/ObjectAndCollectionInitializers.md" "b/data/1..NET\345\210\235\351\230\266/3.C#\347\211\271\346\200\247/1.C#3.0\347\211\271\346\200\247/ObjectAndCollectionInitializers.md" index f6d6ac4c5e31aaecfd00f46f080590b0dcd36b0f..03b483a3874b7fbabcd87f7184c4d92f79974d5f 100644 --- "a/data/1..NET\345\210\235\351\230\266/3.C#\347\211\271\346\200\247/1.C#3.0\347\211\271\346\200\247/ObjectAndCollectionInitializers.md" +++ "b/data/1..NET\345\210\235\351\230\266/3.C#\347\211\271\346\200\247/1.C#3.0\347\211\271\346\200\247/ObjectAndCollectionInitializers.md" @@ -1,11 +1,13 @@ -# C# 3.0 特性 对象和集合初始值设定项 +# CSharp 3.0 特性 对象和集合初始值设定项 使用对象初始值设定项,你可以在创建对象时向对象的任何可访问字段或属性分配值,而无需调用后跟赋值语句行的构造函数。 比如下面的Cat类,以往创建对象可能 + ```csharp Cat cat = new Cat(); cat.Name = "Tom"; cat.Age = 10; ``` + 当然可以直接为对象设置初始值,这样可以简化对象的构造,如下例子: ```csharp @@ -25,18 +27,26 @@ public class Cat } } ``` + +下面这段代码示例了使用具有命名类型Cat的对象初始值设定项以及如何调用无参数构造函数。 + ```csharp Cat cat = new Cat { Age = 10, Name = "Fluffy" }; Cat sameCat = new Cat("Fluffy"){ Age = 10 }; ``` -上面这段代码示例了使用具有命名类型Cat的对象初始值设定项以及如何调用无参数构造函数。当然也可以为匿名类型设置初始值: + +当然也可以为匿名类型设置初始值: + ```csharp var testA = new { name = "Gao", age = 996 }; ``` + 下面是一个List集合的初始化例子: + ```csharp List digits = new List { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; ``` + 除了分配字段和属性外,对象初始值设定项还可以设置索引器,如下例子: ```csharp public class MatrixTest @@ -50,6 +60,8 @@ public class MatrixTest } } ``` + +以及例子: ```csharp var identity = new MatrixTest() { @@ -72,8 +84,7 @@ var identity = new MatrixTest() ## 答案 ```csharp -var numbers = new Dictionary() -{ +var numbers = new Dictionary(){ 7 = "seven", 9 = "nine", 13 = "thirteen" @@ -85,8 +96,7 @@ var numbers = new Dictionary() ### A ```csharp -var numbers = new Dictionary() -{ +var numbers = new Dictionary(){ [1] = "one", [9] = "nine", [13] = "thirteen" @@ -107,7 +117,5 @@ var numbers = new Dictionary() ### C ```csharp -var numbers = new Dictionary() -{ -}; +var numbers = new Dictionary(){}; ``` \ No newline at end of file diff --git "a/data/1..NET\345\210\235\351\230\266/3.C#\347\211\271\346\200\247/1.C#3.0\347\211\271\346\200\247/PartialMethod.md" "b/data/1..NET\345\210\235\351\230\266/3.C#\347\211\271\346\200\247/1.C#3.0\347\211\271\346\200\247/PartialMethod.md" index b727947b38cb74b1f1f7d85524efab4e56d046fc..307db98a88ddadbc0659784920c8d8e73a7bb43f 100644 --- "a/data/1..NET\345\210\235\351\230\266/3.C#\347\211\271\346\200\247/1.C#3.0\347\211\271\346\200\247/PartialMethod.md" +++ "b/data/1..NET\345\210\235\351\230\266/3.C#\347\211\271\346\200\247/1.C#3.0\347\211\271\346\200\247/PartialMethod.md" @@ -1,6 +1,6 @@ -# C# 3.0 ֲ +# C# 3.0 特性 分部方法 -ֲڷֲ͵һжǩڸ͵һжʵ֡WPFWinFormĴpartialؼֶķֲ࣬һִʵֿؼijʼһֿȥʵ־巽ȡ +分部方法在分部类型的一部分中定义了签名,并在该类型的另一部分中定义了实现。比如WPF和WinForm的窗体就是用partial关键字定义的分部类,一部分代码可以实现控件的初始化,一部分可以去实现具体方法等。 ```csharp partial class PartialClassTest @@ -23,15 +23,15 @@ partial class PartialClassTest } } ``` -δʾ˷ֲͷִ```Display()```ѡпԴӡַǣ +上面这段代码示例了分部类和方法,执行```Display()```方法在下列选项中可以打印出的字符串是: -## +## 答案 ```csharp Hello CSDN! ``` -## ѡ +## 选项 ### A @@ -48,5 +48,5 @@ null ### C ```csharp -׳쳣 +抛出异常 ``` \ No newline at end of file diff --git "a/data/1..NET\345\210\235\351\230\266/3.C#\347\211\271\346\200\247/1.C#3.0\347\211\271\346\200\247/config.json" "b/data/1..NET\345\210\235\351\230\266/3.C#\347\211\271\346\200\247/1.C#3.0\347\211\271\346\200\247/config.json" index 4a3de9a79546e7bf40590d6f12212747583f44cb..a30ac5d4004fa3859f099702a7f678df52d58620 100644 --- "a/data/1..NET\345\210\235\351\230\266/3.C#\347\211\271\346\200\247/1.C#3.0\347\211\271\346\200\247/config.json" +++ "b/data/1..NET\345\210\235\351\230\266/3.C#\347\211\271\346\200\247/1.C#3.0\347\211\271\346\200\247/config.json" @@ -15,7 +15,10 @@ "AutoImplementedProperties.json", "ExtensionMethod.json", "ExpressionTree.json", - "QueryExpression.json" + "QueryExpression.json", + "PartialMethod.json", + "ObjectAndCollectionInitializers.json", + "ImplicitType.json" ], "keywords_must": [], "keywords_forbid": []