diff --git a/docs/cs.html b/docs/cs.html new file mode 100644 index 00000000..d3abeeee --- /dev/null +++ b/docs/cs.html @@ -0,0 +1,310 @@ + + + + +C# 备忘清单 + & cs cheatsheet & Quick Reference + + + + + + + +

+C# 备忘清单

+

提供基本语法和方法的 C# 快速参考备忘单

+

入门

+

Hello.cs

+
class Hello {
+  // main method
+  static void Main(string[] args)
+  {
+    // 输出: Hello, world!
+    Console.WriteLine("Hello, world!");
+  }
+}
+
+

编译运行(确保在项目目录下)

+
$ dotnet run
+Hello, world!
+
+

变量

+
int intNum = 9;
+long longNum = 9999999;
+float floatNum = 9.99F;
+double doubleNum = 99.999;
+decimal decimalNum = 99.9999M;
+char letter = 'D';
+bool @bool = true;
+string site = "quickref.me";
+var num = 999;
+var str = "999";
+var bo = false;
+
+

原始数据类型

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
数据类型尺寸范围
int4 bytes-2^31^ ^to^ 2^31^-1
long8 bytes-2^63^ ^to^ 2^63^-1
float4 bytes6 ^to^ 7 decimal digits
double8 bytes15 decimal digits
decimal16 bytes28 ^to^ 29 decimal digits
char2 bytes0 ^to^ 65535
bool1 bittrue / false
string2 bytes per charN/A
+ +

注释

+
// 单行注释
+/* 多行
+   注释 */
+// TODO:向 Visual Studio 中的任务列表添加注释
+/// 用于文档的单行注释
+/** 多行 注释 
+    用于文档 **/
+
+

Strings

+
string first = "John";
+string last = "Doe";
+// 字符串连接
+string name = first + " " + last;
+Console.WriteLine(name); // => John Doe
+
+

查看: Strings

+

User Input

+
Console.WriteLine("Enter number:");
+if(int.TryParse(Console.ReadLine(),out int input))
+{
+  // 输入验证
+  Console.WriteLine($"You entered {input}");
+}
+
+ +

条件句

+
int j = 10;
+if (j == 10) {
+  Console.WriteLine("I get printed");
+} else if (j > 10) {
+  Console.WriteLine("I don't");
+} else {
+  Console.WriteLine("I also don't");
+}
+
+

数组

+
char[] chars = new char[10];
+chars[0] = 'a';
+chars[1] = 'b';
+string[] letters = {"A", "B", "C"};
+int[] mylist = {100, 200};
+bool[] answers = {true, false};
+
+

循环

+
int[] numbers = {1, 2, 3, 4, 5};
+for(int i = 0; i < numbers.Length; i++) {
+  Console.WriteLine(numbers[i]);
+}
+
+
+
foreach(int num in numbers) {
+  Console.WriteLine(num);
+}
+
+

C# 字符串

+

字符串连接

+
string first = "John";
+string last = "Doe";
+string name = first + " " + last;
+Console.WriteLine(name); // => John Doe
+
+

字符串插值

+
string first = "John";
+string last = "Doe";
+string name = $"{first} {last}";
+Console.WriteLine(name); // => John Doe
+
+

字符串成员

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
成员说明
Length返回字符串长度的属性
Compare()比较两个字符串的静态方法
Contains()确定字符串是否包含特定的子字符串
Equals()确定两个字符串是否具有相同的字符数据
Format()通过 {0} 表示法和使用其他原语格式化字符串
Trim()从尾随和前导字符中删除特定字符的所有实例。 默认删除前导和尾随空格
Split()删除提供的字符并从两侧的剩余字符中创建一个数组
+ +

逐字字符串

+
string longString = @"I can type any characters in here !#@$%^&*()__+ '' \n \t except double quotes and I will be taken literally. I even work with multiple lines.";
+
+ +

成员示例

+
// 使用 System.String 的属性
+string lengthOfString = "How long?";
+lengthOfString.Length           // => 9
+// 使用 System.String 的方法
+lengthOfString.Contains("How"); // => true
+
+

杂项

+

一般 .NET 条款

+ + + + + + + + + + + + + + + + + + + + + + + + + + +
条款定义
Runtime执行给定的已编译代码单元所需的服务集合
Common Language Runtime (CLR)主要定位、加载和托管 .NET 对象。
CLR 还处理内存管理、应用程序托管、线程协调、执行安全检查和其他低级细节
Managed code.NET 运行时编译和运行的代码。 C#/F#/VB 就是例子
Unmanaged code直接编译为机器代码且不能由 .NET 运行时直接托管的代码。
不包含空闲内存管理、垃圾收集等。从 C/C++ 创建的 DLL 就是示例
+ +
+ diff --git a/index.html b/index.html index a1406ae6..35a4afa7 100644 --- a/index.html +++ b/index.html @@ -49,6 +49,8 @@ CMake + +C# Django @@ -77,6 +79,8 @@ C + +C# @@ -456,6 +460,9 @@ coderduan + + hua03 + hweining