欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#集合類用法實例代碼詳解

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

下面介紹C#的集合類

1ArrayList

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace 動態(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集合類
{
  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("彈出最后一項{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集合類
{
  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出隊");
      foreach (int i in q1)
      {
        Console.WriteLine(i);
      }
      int num=(int)q2.Peek();
      Console.WriteLine("取q2開始處{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集合類
{
  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集合類
{
  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#集合類用法實例代碼詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • WPF實現(xiàn)控件拖動的示例代碼

    WPF實現(xiàn)控件拖動的示例代碼

    這篇文章主要介紹了WPF實現(xiàn)控件拖動的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-08-08
  • C#中判斷一個集合是否是另一個集合的子集的簡單方法

    C#中判斷一個集合是否是另一個集合的子集的簡單方法

    本文介紹利用C#中內(nèi)置的系統(tǒng)函數(shù)判斷一個集合是否是一個集合的子集的方法,此方法代碼量極少,分享給大家。
    2016-04-04
  • C#實現(xiàn)給DevExpress中GridView表格指定列添加進度條

    C#實現(xiàn)給DevExpress中GridView表格指定列添加進度條

    這篇文章主要為大家詳細介紹了如何利用C#實現(xiàn)給DevExpress中GridView表格指定列添加進度條顯示效果,感興趣的小伙伴可以嘗試一下
    2022-06-06
  • C#利用遞歸算法解決漢諾塔問題

    C#利用遞歸算法解決漢諾塔問題

    這篇文章主要為大家介紹了C#如何利用遞歸算法解決經(jīng)典的漢諾塔問題,文中的示例代碼講解詳細,對我們學習C#有一定幫助,需要的可以參考一下
    2022-04-04
  • C#中創(chuàng)建PDF網(wǎng)格并插入圖片的方法

    C#中創(chuàng)建PDF網(wǎng)格并插入圖片的方法

    這篇文章我將向大家演示如何以編程的方式在PDF文檔中創(chuàng)建一個網(wǎng)格,并將圖片插入特定的網(wǎng)格中。對c# pdf 網(wǎng)格 插入圖片的知識感興趣的朋友一起看看吧
    2016-11-11
  • C#利用IDbCommand實現(xiàn)通用數(shù)據(jù)庫腳本執(zhí)行程序

    C#利用IDbCommand實現(xiàn)通用數(shù)據(jù)庫腳本執(zhí)行程序

    在.net 應用中,在數(shù)據(jù)庫中執(zhí)行腳本程序是經(jīng)常用到的功能,如數(shù)據(jù)操作(新增、修改、刪除等),執(zhí)行一個存儲過程等,本文將介紹如何通過利用IDbCommand 實現(xiàn)通用數(shù)據(jù)庫腳本執(zhí)行程序,感興趣的朋友可以參考下
    2024-04-04
  • C#在復雜多線程環(huán)境下使用讀寫鎖同步寫入文件

    C#在復雜多線程環(huán)境下使用讀寫鎖同步寫入文件

    這篇文章介紹了C#在復雜多線程環(huán)境下使用讀寫鎖同步寫入文件的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04
  • C#位運算符的基本用法介紹

    C#位運算符的基本用法介紹

    這篇文章介紹了C#位運算符的基本用法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-08-08
  • C#文件流讀寫和進度回調(diào)示例詳解

    C#文件流讀寫和進度回調(diào)示例詳解

    這篇文章主要給大家介紹了關(guān)于C#文件流讀寫和進度回調(diào)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。
    2018-03-03
  • C#實現(xiàn)的二維數(shù)組排序算法示例

    C#實現(xiàn)的二維數(shù)組排序算法示例

    這篇文章主要介紹了C#實現(xiàn)的二維數(shù)組排序算法,涉及C#針對二維數(shù)組的遍歷、判斷、排序等相關(guān)操作技巧,需要的朋友可以參考下
    2017-12-12

最新評論