회원 로그인
|
List (리스트) (with Unity)
C# List
- 연결 리스트 형태의 항목 리스트를 관리함
1. List 아이템 추가 : List.Add(아이템)
2. List 아이템 삭제 : List.Remove(아이템), List.RemoveAt(인덱스), List.RemoveAll(리스트)
3. List 아이템 인덱스 확인 : List.IndexOf(아이템)
4. List 아이템 삽입 : List.Inser(인덱스, 아이템)
5. List 아이템 갯수 : List.Count
6. List 아이템 클리어 : List.Clear()
배열과 리스트의 차이점?
배열
장점- 접근이 용이
단점- 중간 삽입이 어렵다
리스트
배열의 단점 보완- 앞뒤 포인터(주소)를 이용하여 저장, 앞뒤 주소를 넣음으로서 중간 삽입 쉬움
참고) Array List문
배열 = {리스트1, 리스트2, ......}
list_ex1.unitypackage
리스트 유니티 예제
- 연결 리스트 형태의 항목 리스트를 관리함
1. List 아이템 추가 : List.Add(아이템)
2. List 아이템 삭제 : List.Remove(아이템), List.RemoveAt(인덱스), List.RemoveAll(리스트)
3. List 아이템 인덱스 확인 : List.IndexOf(아이템)
4. List 아이템 삽입 : List.Inser(인덱스, 아이템)
5. List 아이템 갯수 : List.Count
6. List 아이템 클리어 : List.Clear()
배열과 리스트의 차이점?
배열
장점- 접근이 용이
단점- 중간 삽입이 어렵다
리스트
배열의 단점 보완- 앞뒤 포인터(주소)를 이용하여 저장, 앞뒤 주소를 넣음으로서 중간 삽입 쉬움
참고) Array List문
배열 = {리스트1, 리스트2, ......}
using UnityEngine; using System.Collections; using System.Collections.Generic; public class Monster { public int num; public Monster(int num) { this.num = num; } public void Attack() { Debug.Log(this.num + "번 몬스터가 공격을 시작"); } } public class ListStudy : MonoBehaviour { // List<아이템타입> // List<Monster> monsterList; void Start () { monsterList = new List<Monster>(); // 생성 Debug.Log("--------------------"); // 리스트에 10개의 아이템을 추가함 for (int i=0; i < 10; i++) { monsterList.Add(new Monster(i)); } Debug.Log("Monster List Count : " + monsterList.Count); // 지정한 객체랑 같은 아이템의 인덱스를 추출함 Monster monster = new Monster(3); int index = monsterList.IndexOf(monster); Debug.Log("Monster Num : " + index); // 특정 인덱스 또는 아이템을 삭제함 monsterList.RemoveAt(3); // 3번째 리스트 삭제 monsterList.RemoveAt(5); monsterList.RemoveAt(6); monsterList.Remove(new Monster(7)); // new Monster(7) 객체 삭제 Debug.Log("Monster List Count : " + monsterList.Count); Debug.Log("--------------------"); foreach(Monster mon in monsterList) { mon.Attack(); } // 특정 아이템을 5번째 인덱스 사이에 추가함 monsterList.Insert(5, new Monster(6)); // List.Insert(5번째, 객체) Debug.Log("--------------------"); foreach(Monster mon in monsterList) { mon.Attack(); } // 리스트에 클리어함(전부 삭제) monsterList.Clear(); Debug.Log("Monster List Count : " + monsterList.Count); } }
list_ex1.unitypackage
리스트 유니티 예제
- list_ex1.unitypackage (3.3MB) (0)
댓글 0개
| 엮인글 0개
285개(6/15페이지)
번호 | 제목 | 글쓴이 | 조회 | 날짜 |
---|---|---|---|---|
185 | [PHP] 회원가입 + 로그인 스크립트 (with Unity) [2+1] | 푸딩뱃살 | 12240 | 2015.12.06 17:31 |
184 | [C#] C# 추천 서적 | 푸딩뱃살 | 1321 | 2015.12.06 17:16 |
183 | [C/C++] C++ 참고 사이트 | 푸딩뱃살 | 1182 | 2015.12.04 16:13 |
182 | [PHP] 클래스 | 푸딩뱃살 | 3580 | 2015.12.04 14:40 |
181 | [PHP] CodeIgniter(코드이그나이트) | 푸딩뱃살 | 2931 | 2015.12.04 14:40 |
180 | [C#] Delegate (델리게이트) (with Unity) | 푸딩뱃살 | 6267 | 2015.12.01 10:44 |
179 | [PHP] php 함수 | 푸딩뱃살 | 2219 | 2015.11.30 15:33 |
178 | [PHP] Dictionary (딕셔너리) | 푸딩뱃살 | 2868 | 2015.11.27 12:37 |
177 | [PHP] 배열 | 푸딩뱃살 | 2170 | 2015.11.27 12:37 |
176 | [PHP] 변수 선언 / 산술 연산 | 푸딩뱃살 | 2183 | 2015.11.27 11:14 |
175 | [C#] Dictionary (딕셔너리) (with Unity) [3+3] | 푸딩뱃살 | 14483 | 2015.11.25 10:29 |
>> | [C#] List (리스트) (with Unity) | 푸딩뱃살 | 12088 | 2015.11.24 10:22 |
173 | [C#] Generic (제네릭) (with Unity) | 푸딩뱃살 | 4888 | 2015.11.22 12:32 |
172 | [C/C++] Templete (템플릿) | 푸딩뱃살 | 2045 | 2015.11.22 12:15 |
171 | [C#] 키보드 입력 | 푸딩뱃살 | 3570 | 2015.11.21 18:00 |
170 | [C#] 예외와 예외 처리 | 푸딩뱃살 | 4124 | 2015.11.21 17:39 |
169 | [C#] Struct (구조체) (with Unity) | 푸딩뱃살 | 5123 | 2015.11.18 22:08 |
168 | [C#] Property (프로퍼티) (with Unity) | 푸딩뱃살 | 2443 | 2015.11.18 10:50 |
167 | [C#] interface (인터페이스) (with Unity) | 푸딩뱃살 | 3308 | 2015.11.15 17:32 |
166 | [C#] 스트림 (stream) - 문자, 바이너리 읽기/쓰기 | 푸딩뱃살 | 12780 | 2015.11.14 18:24 |