Skip to content

Commit

Permalink
doc: update docs/cs.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed May 20, 2023
1 parent 862813a commit 36482c5
Showing 1 changed file with 74 additions and 64 deletions.
138 changes: 74 additions & 64 deletions docs/cs.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,57 @@ $ dotnet run
Hello, world!
```

### 命名空间
### 命名空间

```cs
//使用时 using 命名名称
//使用时 using 命名名称
using Test;
//创建:
namespace Test{
class Test_className{
//main方法是程序的主入口
public void Myclass(){
console.writeline("Test")
}
class Test_className{
// main方法是程序的主入口
public void Myclass() {
console.writeline("Test")
}
}
}
```

### 访问修饰符
<!--rehype:wrap-class=row-span-2-->

| 声明的可访问性 | 含义 |
|-----|----------------------|
| public | 访问不受限制 |
| protected | 访问限于包含类或派生自包含类的类型 (该类内部和继承类中可以访问) |
| internal | 访问限于当前程序集 |
| protected internal | 访问限于当前程序集或派生自包含类的类型 |
| private | 访问限于包含类 |
| private protected | 访问限于包含类或当前程序集中派生自包含类的类型,自 C# 7.2 之后可用 |
| `public` | 访问不受限制 |
| `protected` | 访问限于包含类或派生自包含类的类型 (该类内部和继承类中可以访问) |
| `internal` | 访问限于当前程序集 |
| `protected internal` | 访问限于当前程序集或派生自包含类的类型 |
| `private` | 访问限于包含类 |
| `private protected` | 访问限于包含类或当前程序集中派生自包含类的类型,自 C# 7.2 之后可用 |
<!--rehype:className=style-list-->

### 字符串

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

查看: [C#字符串](#c-字符串)

### 用户输入

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

### 变量

Expand Down Expand Up @@ -88,29 +114,6 @@ var bo = false;
*/
```

### 字符串

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

查看: [C#字符串](#c-字符串)

### 用户输入

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

### 条件判断

```cs
Expand Down Expand Up @@ -160,29 +163,29 @@ C# 数据类型

| 关键字 | 名称 | System 别名 | 占用空间(Byte) | 数据范围 |
| ------ | ------------ | ----------- | ---------- | ---------------------------------------- |
| bool | 布尔型 | Boolean | 1 | true/false |
| sbyte | 有符号字节型 | SByte | 1 | -128 ~ 127 |
| byte | 字节型 | Byte | 1 | 0 ~ 255 |
| short | 短整型 | Int16 | 2 | -32,768 ~ 32,767 |
| ushort | 无符号短整型 | UInt16 | 2 | 0 ~ 65,535 |
| int | 整型 | Int32 | 4 | -2,147,483,648 ~ 2,147,483,647 |
| uint | 无符号整型 | UInt32 | 4 | 0 ~ 4,294,967,295 |
| long | 长整型 | Int64 | 8 | -2^63 ~ 2^63-1 |
| ulong | 无符号长整型 | UInt64 | 8 | 0 ~ 2^64-1 |
| char | 字符型 | Char | 8 | UTF-16 所编码的字符 |
| float | 单精度浮点型 | Single | 4 | ±1.5x10^45 ~ ±3.4x10^38 |
| double | 双精度浮点型 | Double | 8 | ±5.0x10^-324 ~ ±1.7x10^308 |
| nint | 指针型 | IntPtr | 与指针相同 | 与指针相同(受操作系统和处理器位宽影响) |
| nuint | 无符号指针型 | UIntPtr | 与指针相同 | 与指针相同(受操作系统和处理器位宽影响) |
| `bool` | 布尔型 | `Boolean` | 1 | true/false |
| `sbyte` | 有符号字节型 | `SByte` | 1 | -128 ~ 127 |
| `byte` | 字节型 | `Byte` | 1 | 0 ~ 255 |
| `short` | 短整型 | `Int16` | 2 | -32,768 ~ 32,767 |
| `ushort` | 无符号短整型 | `UInt16` | 2 | 0 ~ 65,535 |
| `int` | 整型 | `Int32` | 4 | -2,147,483,648 ~ 2,147,483,647 |
| `uint` | 无符号整型 | `UInt32` | 4 | 0 ~ 4,294,967,295 |
| `long` | 长整型 | `Int64` | 8 | -2^63 ~ 2^63-1 |
| `ulong` | 无符号长整型 | `UInt64` | 8 | 0 ~ 2^64-1 |
| `char` | 字符型 | `Char` | 8 | UTF-16 所编码的字符 |
| `float` | 单精度浮点型 | `Single` | 4 | ±1.5x10^45 ~ ±3.4x10^38 |
| `double` | 双精度浮点型 | `Double` | 8 | ±5.0x10^-324 ~ ±1.7x10^308 |
| `nint` | 指针型 | `IntPtr` | 与指针相同 | 与指针相同(受操作系统和处理器位宽影响) |
| `nuint` | 无符号指针型 | `UIntPtr` | 与指针相同 | 与指针相同(受操作系统和处理器位宽影响) |
<!--rehype:className=show-header-->

### 基本数据类型

| 关键字 | 名称 | System 别名 | 说明 |
| -------------------------------- | ------------ | ----------- | ------------------------------------------------------------------ |
|除指针型外的全部原始数据类型 | | | 原始数据类型都是值类型,基本数据类型包含部分本质上是引用的数据类型 |
| string | 字符串 | String | 可变长度 |
| decimal | 十进制浮点数 | Decimal | 适合处理货币等计算,16字节长,不遵循 IEEE 754 关于浮点数的规则 |
关键字 | 名称 | System 别名 | 说明
:------ | ------ | ------ | ------
(除指针型外的全部原始数据类型) | - | - | 原始数据类型都是值类型,基本数据类型包含部分本质上是引用的数据类型
`string` | 字符串 | `String` | 可变长度
`decimal` | 十进制浮点数 | `Decimal` | 适合处理货币等计算,16字节长,不遵循 IEEE 754 关于浮点数的规则
<!--rehype:className=show-header-->

C# 字符串
Expand Down Expand Up @@ -268,23 +271,30 @@ Console.WriteLine(multiLine); // => Content begin "Hello World!" /\n<>"" end.

### 字符串操作

#### 字符串分割

```cs
//字符串分割
string Name = "字A符A串A分A割";
string[] Names=Name.Split(new char[] { 'A' });
//会以A为媒介把字符串分成若干份
for (int i = 0; i < Names.Length; i++)
{
Console.Write(Names[i]);
}
//-----------------------------------
//字符串截取
```

#### 字符串截取

```cs
string Str = "字符串截取";
Str = Str.Substring(2, 1);
Console.WriteLine(Str);
//输出结果“串”,意为从第二个下标开始截取一位字符
//-----------------------------------
//字符串替换
```

#### 字符串替换

```cs
string Rep = "字符1替换";
Rep = Rep.Replace("1", "");
Console.WriteLine(Rep);
Expand Down Expand Up @@ -339,8 +349,8 @@ null | null | null | null | null | null

概念 | 中文名 | 定义
:- | -|--
Runtime | 运行时 | 执行给定的已编译代码单元所需的服务集合
Common Language Runtime (CLR) | 通用语言运行库 | 主要定位、加载和托管 .NET 对象。<br/>CLR 还处理内存管理、应用程序托管、线程协调、执行安全检查和其他低级细节
Managed code | 托管代码 | 在 `.NET` 运行时编译和运行的代码。 C#/F#/VB 就是例子
Unmanaged code | 非托管代码 | 直接编译为机器代码且不能由 .NET 运行时直接托管的代码。<br/>不包含空闲内存管理、垃圾收集等。从 C/C++ 创建的 DLL 就是示例
`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-->

0 comments on commit 36482c5

Please sign in to comment.