C#数组冒泡

string[,] s2 = new string[2, 3] { { "a", "b","c" }, { "d", "e", "f" } };
for (int i = 0; i < 2;i++ ) {
for (int j = 0; j < 3;j++ ) {
Console.WriteLine(s2[i,j]);
}
}
Console.ReadLine();

冒泡排序
int[] a = new int[] { 3,2,4,5,1};
for (int i = 0; i < a.Length - 1;i++ ) {
for (int j = i + 1; j < a.Length;j++ ) {
if(a[i]>a[j]){
int f = a[i];
a[i] = a[j];
a[j] = f;
}
}
}
for (int i = 0; i < a.Length;i++ ) {
Console.WriteLine(a[i]);
}
Console.ReadLine();

二维数组:
string[,] s2 = new string[2,3] { {"a","b","c"}, {"d","e","f" } };
for (int i = 0; i < 2;i++ ) {
for (int j = 0; j < 3;j++ ) {
Console.WriteLine(s2[i,j]); //把所有的都遍历出来 二维取值:名字[1,1]
}
}
Console.ReadLine();


三维数组
string[, ,] s3 = new string[2, 3, 4] {
{ { "1", "2", "3", "4" }, { "", "", "", "" }, { "", "", "", "" } },
{ { "1", "2", "3", "4" }, { "", "", "", "" }, { "", "", "", "" } }
};
意思是这个数组里,有两个二维数组,每个二维数组里有三个一维数组,每个一维数组里有四个变量

原文地址:https://www.cnblogs.com/yunpeng521/p/6991128.html