Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 |
Tags
- 해쉬맵
- 인프런
- list
- 리스트
- map
- 트리
- 큐
- 힙영역
- 벡터
- 알고리즘
- static_cast
- 멀티쓰레드
- Queue
- 객체지향
- std::map
- 반복문
- 프래그멘테이션
- std::unordered_map
- thread
- 배열
- 스택영역
- MonoBehaviour
- 차이점
- 기술면접
- rookiss
- 공부
- c#
- vector
- 자료구조
- 스택
Archives
- Today
- Total
호빵의 IT 개발소
[C#] Dictionary 본문
1. 몬스터 불러오기
dic[] - 몇번 몬스터 불러오기
class Program
{
class Monster
{
public int id;
public Monster(int id) { this.id = id; }
}
static void Main(string[] args)
{
List<int> list = new List<int>();
//Key -> Value
Dictionary<int, Monster> dic = new Dictionary<int, Monster>();
for (int i = 0; i < 10000; i++) //10000개의 몬스터 생성
{
dic.Add(i, new Monster(i));
}
Monster mon = dic[5000]; //5000번 몬스터 불러오기
}
}
2. 몬스터가 있나요?
TryGetValue() - bool형식으로 반환
class Program
{
class Monster
{
public int id;
public Monster(int id) { this.id = id; }
}
static void Main(string[] args)
{
List<int> list = new List<int>();
//Key -> Value
Dictionary<int, Monster> dic = new Dictionary<int, Monster>();
for (int i = 0; i < 10000; i++) //10000개의 몬스터 생성
{
dic.Add(i, new Monster(i));
}
Monster mon;
bool found = dic.TryGetValue(20000, out mon); //bool형식으로 false 반환
}
}
3. 몬스터 삭제
Remove() - 삭제
Clear() - 전체삭제
class Program
{
class Monster
{
public int id;
public Monster(int id) { this.id = id; }
}
static void Main(string[] args)
{
List<int> list = new List<int>();
//Key -> Value
Dictionary<int, Monster> dic = new Dictionary<int, Monster>();
for (int i = 0; i < 10000; i++) //10000개의 몬스터 생성
{
dic.Add(i, new Monster(i));
}
dic.Remove(7777); //7777번 몬스터 삭제
dic.Clear(); //전체 삭제
}
}
---------------------------------------------------------------------------------------------------------------------------
참고 : [인프런] Rookiss님의 [C#과 유니티로 만드는 MMORPG 게임 개발 시리즈] Part1: C# 기초 프로그래밍 입문
'자료구조와 알고리즘 > 자료구조와 알고리즘 맛보기' 카테고리의 다른 글
| [C#] 연결 리스트 (0) | 2022.01.11 |
|---|---|
| [C#] 동적 배열 구현 (0) | 2022.01.11 |
| [C#] 배열, 동적 배열, 연결 리스트 비교 (0) | 2022.01.10 |
| Big-O 표기법 (0) | 2022.01.10 |
| [C#] 배열 맛보기 (0) | 2022.01.05 |
Comments