[C#] Stack, Queue, Hashtable

c# 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

'c#' 카테고리의 다른 글

[C#] Linq  (0) 2023.01.11
[C#] 람다식  (0) 2023.01.11
[C#] 이벤트 핸들러  (0) 2023.01.11
[C#] Delegate  (0) 2023.01.10
[C#] 추상클래스  (0) 2023.01.10
Posted by 바르마스
,