• C#其他


    1.switch - if ...else if...
    switch(表达式)
      {
        case 值:
        。。。。。
        break;
        case 值:
        。。。。。
        break;
        default:
        。。。。。
        break;
      }

    2.while -- for
    int i = 0;//变量初化。
    while(循环条件)
      {

      //循环体
      //i++;//状态改变。
      }
    do...while();

    foreach(元素类型 变量 in 集合或数组)
      {
      }

    3.锯齿数组——数组的数组
    定义:
    a.定义数组的数组:
    int[][] a = new int[3][];
    b.定义一维数组:
    int[] b1 = new int[4]{1,2,3,4};
    int[] b2 = new int[3]{5,6,7};
    int[] b3 = new int[5]{9,10,11,12,13};
    c.把一维数组加到数组的数组中去
    a[0] = b1;
    a[1] = b2;
    a[2] = b3;

    使用:
    a[行][列] = 。。。
    a[行][列]

    a.Length == ??? 3
    a[0].Length = ????? 4

    4.集合:
    (1)链表——每个存储的值都会分配一个索引号,通过索引号可对每个元素赋值或取值。
    弱类型:
    using System.Collection;
    ArrayList list = new ArrayList();

    强类型:
    using System.Collection.Generic;
    List<类型> list = new List<类型>();

    list.Clear();
    list.Add(value);
    list.Insert(索引号,value);
    list.RemoveAt(索引号);
    list.Count;

    (2)哈希表——每个元素都由两部分组成,一部分叫key,一部分叫value
    弱类型:
    using System.Collection;
    Hashtable table = new Hashtable();

    强类型:
    using System.Collection.Generic;
    Dictionary<类型,类型> dic = new Dictionary<类型,类型>();

    dic.Clear();
    dic.Add(key,value);
    dic.Remove(key)
    dic.Count;


    5.递归——自己调自己 —— 将来可能会用到,但是现在仅做了解。

    int Add(int a)
      {
        int b = Add(a+1);
        Console.WriteLine(b);
      }

    void 讲故事()
      {
        Console.Write("从前。。。,老和尚说:");
        讲故事();
      }

    void 找子级文件夹(当前文件夹)
      {
        if(当前文件夹下没有子文件夹)
        {
          return;
        }
      找子级文件夹(当前文件夹下的第一个子文件夹);
      }


    //猴子吃桃子。
    static int TaoZi(int day) //接收天数,返回这一天的桃子数
      {
        if (day == 7)
        {
          return 1;
        }
        int c = (TaoZi(day+1) + 1) * 2;
        return c;
      }

    //程序员与富翁:
    static double Money(int day)
      {
        if (day == 1)
        {
          return 0.01;
        }
        double a = Money(day-1) * 2;
        return a;
      }
    6.枚举:——结构体。枚举也是我们自己定义的类型。

  • 相关阅读:
    54.Spiral Matrix
    53.Maximum Subarray
    基础数据类型包装类
    sqlacodegen逆向数据库
    第四章、常用模块
    第三章、函数编程
    第一章
    第一章 Python基础
    Centos7.0升级python 2.x到3.x
    time
  • 原文地址:https://www.cnblogs.com/liujiangping/p/4534264.html
Copyright © 2020-2023  润新知