最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#集合類(lèi)用法實(shí)例代碼詳解

 更新時(shí)間:2017年10月23日 14:12:33   投稿:mrr  
本文通過(guò)實(shí)例代碼給大家介紹了C#集合類(lèi)用法的相關(guān)知識(shí),非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下

下面介紹C#的集合類(lèi)

1ArrayList

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace 動(dòng)態(tài)數(shù)組ArrayList
{
  class Program
  {
    static void Main(string[] args)
    {
      ArrayList a1 = new ArrayList();
      a1.Add(100);
      foreach (int number in new int[6] { 9, 3, 7, 2, 4, 8 })
      {
        a1.Add(number);
      }
      int[] number2 = new int[2] { 11, 12 };
      a1.AddRange(number2);
      a1.Remove(3);
      a1.RemoveAt(3);
      ArrayList al2 = new ArrayList(a1.GetRange(1,3));
      Console.WriteLine("遍歷方法1:");
      foreach (int i in a1)
      {
        Console.WriteLine(i);
      }
      Console.WriteLine("遍歷方法2:");
      for (int i = 0; i < al2.Count; i++)
      {
        Console.WriteLine(al2[i]);
      }
      Console.ReadLine();
    }
  }
}

2 Stack

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace Stack集合類(lèi)
{
  class Program
  {
    static void Main(string[] args)
    {
      Stack s1 = new Stack();
      Stack s2 = new Stack();
      foreach (int i in new int[4] { 1, 2, 3, 4 })
      {
        s1.Push(i);
        s2.Push(i);
      }
      foreach (int i in s1)
      {
        Console.WriteLine(i);
      }
      s1.Pop();
      Console.WriteLine("出棧");
      foreach (int i in s1)
      {
        Console.WriteLine(i);
      }
      int num=(int)s2.Peek();
      Console.WriteLine("彈出最后一項(xiàng){0}",num);
      foreach (int i in s2)
      {
        Console.WriteLine(i);
      }
      Console.ReadLine();
    }
  }
}

3Queue

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

using System.Collections;
namespace Queue集合類(lèi)
{
  class Program
  {
    static void Main(string[] args)
    {
      Queue q1 = new Queue();
      Queue q2 = new Queue();
      foreach(int i in new int [4]{1,2,3,4})
      {
        q1.Enqueue(i);
        q2.Enqueue(i);
      }
      foreach (int i in q1)
      {
        Console.WriteLine(i);
      }
      q1.Dequeue();
      Console.WriteLine("q1出隊(duì)");
      foreach (int i in q1)
      {
        Console.WriteLine(i);
      }
      int num=(int)q2.Peek();
      Console.WriteLine("取q2開(kāi)始處{0}",num);
      foreach(int i in q2)
      {
        Console.WriteLine(i);
      }
      Console.ReadLine();
    }
  }
}

4Hashtable

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace Hashtable集合類(lèi)
{
  class Program
  {
    static void Main(string[] args)
    {
      Hashtable h = new Hashtable();
      h.Add("E","e");
      h.Add("B", "b");
      h.Add("C", "c");
      h.Add("A", "a");
      foreach (DictionaryEntry e in h)
      {
        Console.Write("{0},{1} ", e.Key, e.Value);
      }
      Console.WriteLine();
      string s = (string)h["C"];
      Console.WriteLine(s);
      if (h.Contains("E"))
      {
        Console.WriteLine("含有E");
      }
      Console.WriteLine(h["A"]);
      h.Remove(h["A"]);
      h.Clear();
      foreach (DictionaryEntry e in h)
      {
        Console.Write("{0},{1} ", e.Key, e.Value);
      }
      Console.ReadLine();
    }
  }
}

5SortedList

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

using System.Collections;
namespace SortedList集合類(lèi)
{
  class Program
  {
    static void Main(string[] args)
    {
      SortedList s1 = new SortedList();
      s1["c"]=41;
      s1["a"]=42;
      s1["d"]=11;
      s1["b"]=13;
      foreach (DictionaryEntry e in s1)
      {
        string s = (string)e.Key;
        int i = (int)e.Value;
        Console.Write("{0},{1} ",s,i);
      }
      Console.ReadLine();
    }
  }
}

總結(jié)

以上所述是小編給大家介紹的C#集合類(lèi)用法實(shí)例代碼詳解,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • C#搜索文字在文件及文件夾中出現(xiàn)位置的方法

    C#搜索文字在文件及文件夾中出現(xiàn)位置的方法

    這篇文章主要介紹了C#搜索文字在文件及文件夾中出現(xiàn)位置的方法,涉及C#針對(duì)文件及文件夾遍歷與查找的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-08-08
  • Base64編碼解碼原理及C#編程實(shí)例

    Base64編碼解碼原理及C#編程實(shí)例

    這篇文章主要介紹了Base64編碼解碼原理及C#編程實(shí)例,本文講解了Base64編碼由來(lái)、Base64編碼原理、C#編程實(shí)現(xiàn),需要的朋友可以參考下
    2014-10-10
  • 詳解c#讀取XML的實(shí)例代碼

    詳解c#讀取XML的實(shí)例代碼

    XML文件是一種常用的文件格式,本篇文章主要介紹了c#讀取XML的實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-12-12
  • C#實(shí)現(xiàn)的文件批量重命名功能示例

    C#實(shí)現(xiàn)的文件批量重命名功能示例

    這篇文章主要介紹了C#實(shí)現(xiàn)的文件批量重命名功能,結(jié)合具體實(shí)例形式分析了C#針對(duì)文件的遍歷、屬性修改相關(guān)操作技巧,需要的朋友可以參考下
    2017-07-07
  • C#獲取所有進(jìn)程的方法

    C#獲取所有進(jìn)程的方法

    在本篇文章里小編給大家分享了關(guān)于C#獲取所有進(jìn)程的方法和步驟,有需要的朋友們跟著學(xué)習(xí)參考下。
    2018-12-12
  • C#操作excel打印的示例

    C#操作excel打印的示例

    這篇文章主要介紹了C#操作excel打印的示例,幫助大家利用c#打印表格,提高辦公效率,感興趣的朋友可以了解下
    2020-10-10
  • C#實(shí)現(xiàn)遞歸算法經(jīng)典實(shí)例

    C#實(shí)現(xiàn)遞歸算法經(jīng)典實(shí)例

    這篇文章主要為大家介紹了C#實(shí)現(xiàn)遞歸算法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-01-01
  • C#迭代器方法介紹

    C#迭代器方法介紹

    這篇文章主要介紹了C#迭代器方法,可以使用foreach循環(huán)語(yǔ)句進(jìn)行的迭代的方法,稱(chēng)為可迭代方法,或者迭代器方法,方法操作,想了解更多內(nèi)容得小伙伴可以學(xué)習(xí)下面文章內(nèi)容,希望給你的學(xué)習(xí)帶來(lái)幫助
    2022-03-03
  • C# Winform 實(shí)現(xiàn)TCP發(fā)消息

    C# Winform 實(shí)現(xiàn)TCP發(fā)消息

    這篇文章主要介紹了C# Winform 實(shí)現(xiàn)TCP發(fā)消息的示例,幫助大家更好的理解和學(xué)習(xí)使用c#技術(shù),感興趣的朋友可以了解下
    2021-03-03
  • C#定義并實(shí)現(xiàn)單鏈表實(shí)例解析

    C#定義并實(shí)現(xiàn)單鏈表實(shí)例解析

    這篇文章主要介紹了C#定義并實(shí)現(xiàn)單鏈表實(shí)例解析,有助于讀者加深對(duì)C#實(shí)現(xiàn)數(shù)據(jù)結(jié)構(gòu)的理解,需要的朋友可以參考下
    2014-07-07

最新評(píng)論

泸定县| 禄丰县| 靖西县| 缙云县| 桐乡市| 长垣县| 南投市| 祥云县| 横峰县| 石嘴山市| 滨州市| 平泉县| 沙河市| 曲松县| 集安市| 津南区| 花莲县| 尼玛县| 中宁县| 探索| 古交市| 卓尼县| 同心县| 安塞县| 从江县| 溆浦县| 洮南市| 德阳市| 顺昌县| 拜城县| 平潭县| 延寿县| 莎车县| 南丰县| 阳城县| 山东省| 广州市| 格尔木市| 定安县| 冀州市| 海兴县|