zoukankan      html  css  js  c++  java
  • 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" }, { "", "", "", "" }, { "", "", "", "" } }
    };
    意思是这个数组里,有两个二维数组,每个二维数组里有三个一维数组,每个一维数组里有四个变量

  • 相关阅读:
    面向对象的设计模式2
    数据结构
    算法题目1
    5.7(1) 反射
    hashMap原理(java8)
    6.1 接口
    18.1 线程
    13.2 具体的集合
    scrapy(2)——scrapy爬取新浪微博(单机版)
    5.1 类、超类和子类
  • 原文地址:https://www.cnblogs.com/yunpeng521/p/6991128.html
Copyright © 2011-2022 走看看