feat: add cs.md #66
This commit is contained in:
parent
aaa0f1f523
commit
2200972ce7
@ -21,6 +21,7 @@ Quick Reference
|
||||
|
||||
[Ansible](./docs/ansible.md)<!--rehype:style=background: rgb(238 0 0/var(\-\-bg\-opacity));&class=contributing tag&data-lang=RedHad&data-info=👆看看还缺点儿什么?-->
|
||||
[CMake](./docs/cmake.md)<!--rehype:style=background: rgb(92 107 192/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[C#](./docs/cs.md)<!--rehype:style=background: rgb(6 147 13/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=contributing tag&data-lang=Python-->
|
||||
[FFmpeg](./docs/ffmpeg.md)<!--rehype:style=background: rgb(0 193 9/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[LaTeX](./docs/latex.md)<!--rehype:style=background: rgb(0 128 128/var(\-\-bg\-opacity));&class=contributing-->
|
||||
@ -32,6 +33,7 @@ Quick Reference
|
||||
|
||||
[Bash](./docs/bash.md)<!--rehype:style=background: rgb(72 143 223/var(\-\-bg\-opacity));-->
|
||||
[C](./docs/c.md)<!--rehype:style=background: rgb(92 107 192/var(\-\-bg\-opacity));-->
|
||||
[C#](./docs/cs.md)<!--rehype:style=background: rgb(6 147 13/var(\-\-bg\-opacity));&class=contributing-->
|
||||
[Dart](./docs/dart.md)<!--rehype:style=background: rgb(64 196 255/var(\-\-bg\-opacity));-->
|
||||
[Docker](./docs/docker.md)<!--rehype:style=background: rgb(72 143 223/var(\-\-bg\-opacity));-->
|
||||
[Dockerfile](./docs/dockerfile.md)<!--rehype:style=background: rgb(0 72 153/var(\-\-bg\-opacity));&class=tag&data-lang=Docker-->
|
||||
|
200
docs/cs.md
Normal file
200
docs/cs.md
Normal file
@ -0,0 +1,200 @@
|
||||
C# 备忘清单
|
||||
===
|
||||
|
||||
提供基本语法和方法的 C# 快速参考备忘单
|
||||
|
||||
入门
|
||||
--------
|
||||
|
||||
### Hello.cs
|
||||
|
||||
```cs
|
||||
class Hello {
|
||||
// main method
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// 输出: Hello, world!
|
||||
Console.WriteLine("Hello, world!");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
编译运行(确保在项目目录下)
|
||||
|
||||
```shell
|
||||
$ dotnet run
|
||||
Hello, world!
|
||||
```
|
||||
|
||||
### 变量
|
||||
|
||||
```cs
|
||||
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;
|
||||
```
|
||||
|
||||
### 原始数据类型
|
||||
|
||||
数据类型 | 尺寸 | 范围
|
||||
:- | - | -
|
||||
| `int` | 4 bytes | -2^31^ ^to^ 2^31^-1 |
|
||||
| `long` | 8 bytes | -2^63^ ^to^ 2^63^-1 |
|
||||
| `float` | 4 bytes | 6 ^to^ 7 decimal digits |
|
||||
| `double` | 8 bytes | 15 decimal digits |
|
||||
| `decimal` | 16 bytes | 28 ^to^ 29 decimal digits |
|
||||
| `char` | 2 bytes | 0 ^to^ 65535 |
|
||||
| `bool` | 1 bit | true / false |
|
||||
| `string` | 2 bytes per char | _N/A_ |
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
### 注释
|
||||
|
||||
```cs
|
||||
// 单行注释
|
||||
/* 多行
|
||||
注释 */
|
||||
// TODO:向 Visual Studio 中的任务列表添加注释
|
||||
/// 用于文档的单行注释
|
||||
/** 多行 注释
|
||||
用于文档 **/
|
||||
```
|
||||
|
||||
### Strings
|
||||
|
||||
```cs
|
||||
string first = "John";
|
||||
string last = "Doe";
|
||||
// 字符串连接
|
||||
string name = first + " " + last;
|
||||
Console.WriteLine(name); // => John Doe
|
||||
```
|
||||
|
||||
查看: [Strings](#c-字符串)
|
||||
|
||||
### User Input
|
||||
|
||||
```cs
|
||||
Console.WriteLine("Enter number:");
|
||||
if(int.TryParse(Console.ReadLine(),out int input))
|
||||
{
|
||||
// 输入验证
|
||||
Console.WriteLine($"You entered {input}");
|
||||
}
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 条件句
|
||||
|
||||
```cs
|
||||
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");
|
||||
}
|
||||
```
|
||||
|
||||
### 数组
|
||||
|
||||
```cs
|
||||
char[] chars = new char[10];
|
||||
chars[0] = 'a';
|
||||
chars[1] = 'b';
|
||||
string[] letters = {"A", "B", "C"};
|
||||
int[] mylist = {100, 200};
|
||||
bool[] answers = {true, false};
|
||||
```
|
||||
|
||||
### 循环
|
||||
|
||||
```cs
|
||||
int[] numbers = {1, 2, 3, 4, 5};
|
||||
for(int i = 0; i < numbers.Length; i++) {
|
||||
Console.WriteLine(numbers[i]);
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cs
|
||||
foreach(int num in numbers) {
|
||||
Console.WriteLine(num);
|
||||
}
|
||||
```
|
||||
|
||||
C# 字符串
|
||||
----------------
|
||||
|
||||
### 字符串连接
|
||||
|
||||
```cs
|
||||
string first = "John";
|
||||
string last = "Doe";
|
||||
string name = first + " " + last;
|
||||
Console.WriteLine(name); // => John Doe
|
||||
```
|
||||
|
||||
### 字符串插值
|
||||
|
||||
```cs
|
||||
string first = "John";
|
||||
string last = "Doe";
|
||||
string name = $"{first} {last}";
|
||||
Console.WriteLine(name); // => John Doe
|
||||
```
|
||||
|
||||
### 字符串成员
|
||||
<!--rehype:wrap-class=row-span-2-->
|
||||
|
||||
成员 | 说明
|
||||
:- | -
|
||||
`Length` | 返回字符串长度的属性
|
||||
`Compare()` | 比较两个字符串的静态方法
|
||||
`Contains()` | 确定字符串是否包含特定的子字符串
|
||||
`Equals()` | 确定两个字符串是否具有相同的字符数据
|
||||
`Format()` | 通过 {0} 表示法和使用其他原语格式化字符串
|
||||
`Trim()` | 从尾随和前导字符中删除特定字符的所有实例。 默认删除前导和尾随空格
|
||||
`Split()` | 删除提供的字符并从两侧的剩余字符中创建一个数组
|
||||
<!--rehype:className=show-header-->
|
||||
|
||||
### 逐字字符串
|
||||
|
||||
```cs
|
||||
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.";
|
||||
```
|
||||
<!--rehype:className=wrap-text-->
|
||||
|
||||
### 成员示例
|
||||
|
||||
```cs
|
||||
// 使用 System.String 的属性
|
||||
string lengthOfString = "How long?";
|
||||
lengthOfString.Length // => 9
|
||||
// 使用 System.String 的方法
|
||||
lengthOfString.Contains("How"); // => true
|
||||
```
|
||||
|
||||
杂项
|
||||
-----------
|
||||
|
||||
### 一般 .NET 条款
|
||||
<!--rehype:wrap-class=col-span-2-->
|
||||
|
||||
条款 | 定义
|
||||
:- | -
|
||||
Runtime | 执行给定的已编译代码单元所需的服务集合
|
||||
Common Language Runtime (CLR) | 主要定位、加载和托管 .NET 对象。<br/>CLR 还处理内存管理、应用程序托管、线程协调、执行安全检查和其他低级细节
|
||||
Managed code | 在 `.NET` 运行时编译和运行的代码。 C#/F#/VB 就是例子
|
||||
Unmanaged code | 直接编译为机器代码且不能由 .NET 运行时直接托管的代码。<br/>不包含空闲内存管理、垃圾收集等。从 C/C++ 创建的 DLL 就是示例
|
||||
<!--rehype:className=show-header-->
|
2
scripts/assets/cs.svg
Normal file
2
scripts/assets/cs.svg
Normal file
@ -0,0 +1,2 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="1em" height="1em" viewBox="0 0 200 218">
|
||||
<path d="M100,0.44 L100,0.455333333 L199.666667,58.5993333 L199.666667,159.400667 L100,217.56 L0.333333333,159.400667 L0.333333333,58.5993333 L100,0.44 Z M82.0833333,55.333 C53.8740706,55.3333333 31,78.2074039 31,106.424 L31,111.576 C31.0041913,129.277326 40.1707165,145.7152 55.2277239,155.022373 C70.2847313,164.329546 89.0864906,165.17968 104.922,157.269333 L111.101333,154.202667 L104.232,140.479333 L98.068,143.546 C86.9899096,149.088667 73.8317911,148.500121 63.2927817,141.99055 C52.7537723,135.480978 46.336719,123.978635 46.3333333,111.591333 L46.3333333,106.439333 C46.3346881,94.0500894 52.7491422,82.5443897 63.2870103,76.0292762 C73.8248785,69.5141628 86.9843283,68.9181542 98.068,74.454 L104.232,77.536 L111.101333,63.828 L104.922,60.746 C98.0448161,57.3003013 90.4812112,55.4533442 82.7961467,55.3389754 L82.0833333,55.333 Z M138.333333,70.6666667 L123,70.6666667 L123,86 L107.666667,86 L107.666667,101.333333 L123,101.333333 L123,116.666667 L107.666667,116.666667 L107.666667,132 L123,132 L123,147.333333 L138.333333,147.333333 L138.333333,132 L153.666667,132 L153.666667,147.333333 L169,147.333333 L169,132 L184.333333,132 L184.333333,116.666667 L169,116.666667 L169,101.333333 L184.333333,101.333333 L184.333333,86 L169,86 L169,70.6666667 L153.666667,70.6666667 L153.666667,86 L138.333333,86 L138.333333,70.6666667 Z M153.666667,101.333333 L153.666667,116.666667 L138.333333,116.666667 L138.333333,101.333333 L153.666667,101.333333 Z"/></svg>
|
After Width: | Height: | Size: 1.5 KiB |
Loading…
x
Reference in New Issue
Block a user