본문 바로가기

c#

C# [11] ArrayList, Queue, Stack, Hashtable

728x90
반응형
using System;
using System.Collections;

class Program
{
    public static void Main(string[] args)
    {
        //ArrayList
        ArrayList al = new ArrayList();
        al.Add(1);
        al.Add("Hello");
        al.Add(3.4);
        al.Add(true);

        foreach (var item in al)
        {
            Console.WriteLine(item);
        }

        al.Remove("Hello");
        //Queue
        Queue qu = new Queue();
        qu.Enqueue(1);
        qu.Enqueue(2);

        foreach (var item in qu)
            Console.WriteLine(item);

        qu.Dequeue();

        foreach (var item in qu)
            Console.WriteLine(item);

        //Stack
        Stack st = new Stack();
        st.Push(3);
        st.Push(4);

        foreach (var item in st)
            Console.WriteLine(item);

        st.Pop();

        //HashTable ( key <=== index , value로 구성)

        Hashtable ht = new Hashtable();
        ht.Add("1", "Hello");
        ht.Add("2", "World");
        ht.Add("3", "C#");

        foreach (DictionaryEntry item in ht)
            Console.WriteLine(item.Key + " : " + item.Value);

    }
}
728x90
반응형