프로그래밍/C#
컬렉션 & 제네릭 사용하기
Lucky-John
2021. 11. 3. 00:16
using System.Collections;
string[] colors = {"red", "blue", "green"};
// Array
Array.Sort(colors);
Array.Reverse(colors);
// Stack
Stack stack = new Stack();
stack.Push(100);
stackPop();
// Queue
Queue queue = new Queue();
queue.Enqueue(100);
queue.Dequeue();
// ArrayList
ArrayList list = new ArrayList();
list.Add(10);
list.Add(20);
list.RemoveAt(1);
list.Insert(0, 50);
// HashTable
Hashtable hashtable = new Hashtable();
hashtable[0] = "ABC";
tashtable["NickName"] = "RedPlus";
using System.Collections.Generic;
// Stack
Stack<int> stack = new Stack<int>();
stack.Push(100);
// List
List<int> numbers = new List<int>();
numbers.Add(10);
numbers.Add(20);
// Dictionary
Dictionary<int, string> todos = new Dictionary<int, string>();
todos.Add(1, "AAA");
todos.Add(2, "BBB");
foreach(var item in todos)
{
Console.WriteLine($"{Item.Key} - {item.Value}");
}