语法基础
结构体主要用于创建小型对象,因为在C#中值类型是存储在线程堆栈中的,而线程堆栈的默认大小是1MB。
交错数组
byte[][] months = new byte[12][];
if (month % 2 == 0) {
months[month] = new byte[31];
} else {
months[month] = new byte[30];
}
Dictionary
//创建省份列表
Dictionary<string, List<string>> provinces = new Dictionary<string, List<string>>();
//创建河北省
List<string> HeBei = new List<string>();
//将河北省添加到省份列表中
provinces.Add("河北", HeBei);
//添加城市
HeBei.Add("石家庄");
//添加城市
HeBei.Add("唐山");
Queue
先进先出,Stack
先进后出。
字符串
如果需要删除某个字符串,可以使用Replace
方法,将其第一个参数传入需要删除的字符串,第二个参数输入string.Empty
即可。
Contains
(判断字符串中是否含有指定字符串)、StartsWith
(判断字符串是否以指定字符串开头)、EndWith
(判断字符串是否以指定字符串结尾)在模糊匹配中作用很大。
数据结构与算法
索引器
public class StudentList {
//学生信息顺序表
private Student[] Students;
//检索学生信息表
public Student this[int index] {
get {
return Students[index];
}
set {
Students[index] = value;
}
}
}
int?
表示