c#

[C#] Stack, Queue, Hashtable

바르마스 2023. 1. 11. 12:08
728x90

System.Collection

static void Main(string[] args)
{
        Stack stack = new Stack();
        stack.Push("1스택");
        stack.Push("2스택");
        stack.Push(1);
        stack.Push(2);
        Console.WriteLine(stack.Count);
        foreach (var item in stack) 
        {
            Console.WriteLine(item);
        }

        int[] array = { 10, 20, 30, 40, 50, 60, 70 };
        Queue q = new Queue(array);
        foreach (var a in q)
        {
            Console.WriteLine(a);
        }

        Hashtable ht = new Hashtable();
        ht.Add("이름", "장영실");
        ht.Add("주소", "부산");
        ht.Add("나이", "25");
        Console.WriteLine(ht["주소"]);
        foreach (var a in ht.Keys)
        {
            Console.WriteLine("Key : " + a+ " Value : "+ ht[a]);
        }
        foreach (var a in ht.Values)
        {
            Console.WriteLine("Value : " + a);
        }
}
728x90