배열 Array
-> 참조 타입 변수
foreach
int[] arr = new int[] { 10,20,30,40,50 };
foreach ( int i in arr ){
Console.WriteLine(e)
}
다차원 배열
int [ , ] arr = new int[2,3] ;// 2행 3열 행렬
List<I> <- 제네릭 타입
-> 동적 배열, 배열의 길이를 늘릴 수 있음(물리적으로 연속된 더 큰 주소 할당됨)
namespace CSharp2
{
class Temp
{
public static void Main(string[] args)
{
List<int> list = new List<int>();
list.Add(1);
list.Add(2);
}
}
}
Dictionary 딕셔너리
static void Main(string[] args)
{
List<int> list = new List<int>();
list.Add(1);
list.Add(2);
Dictionary<int, string> dic = new Dictionary<int, string>();
//Dictionary<keyType, valueType>
//내부적으로 hashTable로 구현됨
//->각각의 key값에 해시 함수를 적용해
//배열의 고유한 인덱스를 생성, 이 인덱스를 활용해 값을 저장
dic.Add(1, "slime");
dic[2] = "orc";
dic[3] = "skeleton";
string str = "";
bool b = dic.TryGetValue( 4, out str);
Console.WriteLine(b);//False
}
'c# 입문' 카테고리의 다른 글
[c#] 제네릭 타입, 프로퍼티 (0) | 2022.07.17 |
---|---|
[c#] 다운 캐스팅, 오버라이딩, base (0) | 2022.07.17 |
[c#] c# 상속성 (0) | 2022.07.09 |
[c#] CSharp this 키워드, static키워드 (0) | 2022.07.09 |
[c#] 복사(copy)타입 변수와 참조(ref)타입 변수 (0) | 2022.07.09 |