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.";