C#

C# - ArrayList, Queue, Stack, Hashtable

마루설아 2024. 12. 10. 20:35
using System;
using System.Collections;

class Program
{
     static void Main(String[] args)
     {
          // ArrayList
          ArrayList a = new ArrayList();
          a.Add(3);
          a.Add("MaruCoding");
          a.Add(true);
          a.Remove(3);

          foreach(var v in a)
          {
               Console.Write(v + " ");
          }
          Console.WriteLine();


          // Queue
          Queue q = new Queue();
          q.Enqueue(1);
          q.Enqueue("Maru");
          q.Enqueue(false);

          while(q.Count != 0)
          {
               Console.Write(q.Dequeue() + " ");
          }
          Console.WriteLine();


          // Stack
          Stack s = new Stack();
          s.Push(3.3);
          s.Push("Code");
          s.Push('Z');

          while(s.Count != 0)
          {
               Console.Write(s.Pop() + " ");
          }
          Console.WriteLine();


          // Hashtable
          Hashtable h = new Hashtable();
          h["who"] = "maru";
          h["age"] = 25;
          h["tf"] = true;

          Console.WriteLine(h["who"]);
     }
}

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

C# - Unity 마우스 이벤트  (0) 2024.12.11
C# - Unity 스크립트 생성 및 로그 확인  (0) 2024.12.11
C# - Unity 환경 설정  (0) 2024.12.11
C# - 예외처리  (0) 2024.12.10
C# - 배열 선언 방법  (0) 2024.12.10