HaPpY hApPy
1. 데이터 멤버 대신에 항상 프로퍼티를 사용하라. 본문
1. 프라퍼티에 이렇게 숫자 인덱스를 붙여서 사용하는 방법도 있고
public int this[int index]
{
get { return theValues[index]; }
set { theValues[index] = value; }
}
2. 이렇게 문자열 인덱스를 사용하여 맵이나 디렉토리와 같은 자료구조의 표현도 가능하다
public Address this[string name]
{
get { return adressValues[name]; }
set { adressValues[name] = value; }
}
3. 위 2개를 섞어 사용할수도 있다.
public int this[int x, string name]
{
get { return ComputeValue(x, name); }
}
이 쯤에서 간단히 끝!
'.NET > Effective C#' 카테고리의 다른 글
5. 항상 ToString()을 작성하라. (0) | 2013.08.17 |
---|---|
4. #if 대신 Conditional Attribute를 사용하라. (0) | 2013.08.17 |
3. cast보다는 is나 as가 좋다. (0) | 2013.08.17 |
2. const 보다는 readonly가 좋다 (0) | 2013.08.17 |
Effective C# (0) | 2013.08.17 |