数组
1、数组是一个存储相同类型元素的固定大小的顺序集合
2、某个指定的元素是通过索引来访问的
3、所有的数组都是由连续的内存位置组成的。最低的地址对应第一个元素,最高的地址对应最后一个元素
int[] arr = new int[3] {1,3,56};
int[] arr = {1,3,4};
多维数组
double[,] points = { { 80, 90 }, { 85, 95 }, { 100, 100 } };
Console.WriteLine(points.Length); //6
Console.WriteLine(points.GetLength(0));//3
Console.WriteLine(points.GetLength(1));//2
// 锯齿形数组
int[][] arrays = new int[2][];
arrays[0] = new int[] { 1, 2 };
arrays[1] = new int[] { 3, 4, 5 };
冒泡排序 Sort()方法
int[] a = { 5, 1, 7, 2, 3 };
Array.Sort(a);
for (int i = 0; i < a.Length; i++) //0,1,2,3,4
{
for (int j = 0; j < a.Length - i - 1; j++)//(0,1,2,3)(0,1,2)
{
if (a[j] > a[j + 1])
{
int temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
//Reverse() 将数组中的元素逆序排列
枚举
访问修饰符 enum 变量名 : 数据类型
{
值l,
值2,
}
//数据类型只能是整数类型,包括 byte、short、int、long 等
//默认是从 0 开始的,也就是值 1 的值是 0、值 2 的值是 1(值是递增加 1)。
结构体
结构体与类比较相似,由于它是值类型,在使用时会比使用类存取的速度更快,但灵活性方面没有类好。
访问修饰符 struct 结构体名称
{
//结构体成员
}