![[C#] 16일차 - 112. 인덱서](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcGfiQ2%2FbtqXgopuwX0%2FpxjcWXrde7ySqXkJtzISf1%2Fimg.png)
인덱서는 인스턴스 내의 데이터에 접근하는 방법입니다. -> 배열이 아닌데 배열처럼 쓸 수 있게 만들어준다. 인덱서는 this[]를 사용해며 getter와 setter를 만듭니다. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A112_Indexer { class MyCollection { private T[] array = new T[100]; // 인덱서 정의 -> 배열이 아닌데 배열처럼 쓸수있게만들어준다 public T this[int i] { get { return array[i]; } set { array[i] = val..
![[C#] 16일차 - 111. SortedList와 SortedList<Tkey, Tvalue>](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FmOHQg%2FbtqW1szM26E%2FvLyc0APG1N9klbF9rCTK60%2Fimg.png)
SortedList는 key의 오름차순으로 키-값 쌍을 저장한다. 새로운 값이 들어오면 키를 이진탐색해 적절한 인덱스를 찾고 그 곳에 키-값 쌍을 저장한다. SortedLis는 기본적으로 key는 int / value는 string타입으로 저장한다. -> 다르게도 지정가능 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A111_SortedList { class Program { static void Main(string[] args) { SortedList s1 = new SortedList(); s1.Add(3, "Three"..
![[C#] 16일차 - 110. Hashtable과 Dictionary<Tkey, Tvalue>](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FVvWQm%2FbtqXb2ttX9j%2FImcFy2fg0En3glu3ZBqmJ0%2Fimg.png)
사용시 주의사항 키는 중복될 수 없다. 중복된 키로 저장하면 ArgumentException이 발생한다 없는 키로 Hashtable에 접근하면 KeyNotFoundException이 발생한다. 배열에서와 같은 순차적인 숫자 인덱스를 사용할 수 없다. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A110_Dictionary { class Program { static void Main(string[] args) { Dictionary colorTable = new Dictionary(); colorTable.Add("Red", ..
![[C#] 16일차 - 109. Stack<T>와 Polish 계산기](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FGMS6D%2FbtqW1s7CCet%2FIzK8F2T1n5SuFnBRfCZrk0%2Fimg.png)
polish 표기법은 피연산자 뒤에 연산자를 쓰게 된다. 1 + 2 를 1 2 + 로 표시한다. 이렇게 되면 수식에 괄호가 없어도 우선순위를 처리할 수 있게된다. 예를들어 (10 - 20) * 3 이라는 수식을 10 20 - 3 * 로 처리 할 수 있다. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A109_Stack { class Program { static void Main(string[] args) { Console.Write("계산할 수식을 Polish 표기법으로 입력하세요: "); string[] token = Co..
![[C#] 16일차 - 108. Queue<T> 컬렉션의 사용 방법](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FmEOcG%2FbtqWX4FUNFg%2FlYmmqO4KKyK27ltsBKK1T0%2Fimg.png)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A108_Queue { class Program { static void Main(string[] args) { Queue que = new Queue(); que.Enqueue("Tiger"); que.Enqueue("Lion"); que.Enqueue("Zebra"); que.Enqueue("Cow"); que.Enqueue("Rabbit"); PrintQueue("que : ", que); Console.WriteLine(" Dequeuing '{0}'", que.Dequeue..