zoukankan      html  css  js  c++  java
  • 数组和集合

    int[] arr1 = new int[2] {1,2};
    int[,] arr2 = new int[2, 3] {
    {0,1,2 },
    {2,3,4 }
    };

    Console.WriteLine(arr2[1,1]);

    ArrayList
    ArrayList alt = new ArrayList();
    alt.Add("123");
    alt.Add(123);
    alt.Add(true);
    bool iscontain = alt.Contains("1");
    alt.Clear();

    Console.WriteLine(iscontain);

    for(int i = 0; i < alt.Count; i++)
    {
     Console.WriteLine(alt[i].ToString() + " " + alt[i].GetType().ToString());
    }

    foreach (var x in alt)
    {
    Console.WriteLine(x.ToString() + " " + x.GetType().ToString());
    }

    泛型集合 List      注意类型。
    List<string> str_list = new List<string>();
    str_list.Add("a");
    str_list.Add("b");
    str_list.Add("c");
    str_list.Add("d");

    foreach(string x in str_list)
    {
     Console.WriteLine(x);
    }


    哈希表hashtable        可以不写类型。

    Hashtable ht = new Hashtable();
    ht.Add("1","a");
    ht.Add(2, "b");
    ht.Add(3, false);
    ht.Add("x", 3.14);
    Console.WriteLine(ht[2]);
    foreach(var x in ht.Keys)
    {
    Console.WriteLine(ht[x]);
    }

    字典表 Dictionary

    Dictionary<string, int> dic = new Dictionary<string, int>();       写的时候注意类型
    dic.Add("a", 3);
    dic.Add("b", 4);
    dic.Add("c", 5);
    dic.Add("d", 6);
    dic.Add("e", 7);

    foreach(var x in dic.Keys)
    {
     Console.WriteLine(x);
    }

    队列 queue        可以不写类型和长度。

    Queue que = new Queue();
    que.Enqueue("张三");
    que.Enqueue("李四");
    que.Enqueue("王五");
    que.Enqueue("赵六");
    Console.WriteLine("现在的长度是" + que.Count);
    Console.WriteLine(que.Dequeue());
    Console.WriteLine("现在的长度是" + que.Count);

    堆栈 stack

    Stack st = new Stack();
    st.Push("a");
    st.Push("b");
    st.Push("c");
    st.Push("d");

    Console.WriteLine(st.Count);
    Console.WriteLine(st.Pop());
    Console.WriteLine(st.Count);

    Console.ReadLine();

  • 相关阅读:
    springboot + ApplicationListener
    spring-boot集成swagger
    Servlet对象生命周期(四)
    MyEclipse 基本使用(三)
    Servlet视频-开发第一个java web(最简单的java web程序)(二)
    java Servlet学习笔记(一)
    java JDBC
    冒泡和选择排序 事例
    c#转 java学习笔记(原创)
    数据存储、进制转换
  • 原文地址:https://www.cnblogs.com/yunpeng521/p/6992601.html
Copyright © 2011-2022 走看看