• 数组和集合实例


    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApplication2
    {
    class Program
    {
    static void Main(string[] args)
    {
    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();
    /*alt.Insert(0, "abc")*/
    ;
    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();


    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 特点不需要不需要限长度,不需要规定类型,缺点:键值只能是0,1,2,3往后排:

    ArrayList alt = new ArrayList();
    alt.Add("123");
    alt.Add(123);
    alt.Add(true);
    alt.Remove(123); 从其中移除 clear 是全部清空的意思
    bool iscontain=alt.Contains("123"); 看看里面是否包含"123",如果有就会显示"true",如果没有就会显示false;
    alt.Clear(); 全部清除:
    alt.Insert(0,"abc"); 意思是往 0 位置插入一个字符串"123";

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

    }


    var类型是 万能类型
    foreach(var x in alt){

    Console.WriteLine(x.ToString()+" "+alt[i].GetType().ToString)



    }
    泛型集合 list 需要规定类型,不需要规定长度 也不行规定键值 也是从0,1,2,3开始排

    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.Values) {

    Console.WriteLine(x);


    }
    foreach (var x in ht.Keys)
    {

    Console.WriteLine(x); //取全部的值
    Console.WriteLine(ht[x]);

    }

    字典表 Dictionary
    Dictionary<string, int> dic = new Dictionary<string, int>();
    dic.Add("a", 3);
    dic.Add("b", 4); 前面的是key键 后面的是value值
    dic.Add("c", 5);
    dic.Add("d", 6);
    dic.Add("e", 7);
    dic.Add("f", 8);


    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()); //dequeue()函数用于移除每个匹配元素的指定队列中的第一个函数,并执行被移除的函数。
    Console.WriteLine("现在的长度" + que.Count);

    堆栈 stack 先进后出


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

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

    Console.ReadLine();

    }
    }
    }

  • 相关阅读:
    Luogu P3390 【模板】矩阵快速幂&&P1939 【模板】矩阵加速(数列)
    矩阵乘法&&矩阵快速幂&&最基本的矩阵模型——斐波那契数列
    EZ 2018 05 13 NOIP2018 模拟赛(十三)
    Luogu P2341 [HAOI2006]受欢迎的牛
    Deep learning_CNN_Review:A Survey of the Recent Architectures of Deep Convolutional Neural Networks——2019
    常用刷题网址——提高代码能力
    Computer Vision_33_SIFT:Fast Adaptive Bilateral Filtering——2018
    Computer Vision_33_SIFT:An Improved RANSAC based on the Scale Variation Homogeneity——2016
    Computer Vision_33_SIFT:LIFT: Learned Invariant Feature Transform——2016
    Computer Vision_33_SIFT:ORB_An efficient alternative to SIFT or SURF——2012
  • 原文地址:https://www.cnblogs.com/liuyubin0629/p/6993342.html
Copyright © 2020-2023  润新知