C# - Dictionary의 Class, Struct 노드 추가하고 수정시 방법


1. 첫번째.


class Test
{
public struct Point
{
public DateTime lastRecorded;
public TimeSpan totalTime;
public int totalCalls;
}

private Dictionary dic = new Dictionary();

public void SetValue(string tag, out point)
{
dic.TryGetValue(tag, out point);
point.totalCalls= 1;
dic[tag] = point;
}
}




2. 두번째


class Test
{
public struct Point
{
public DateTime lastRecorded;
public TimeSpan totalTime;
public int totalCalls;
}


private Dictionary dic = new Dictionary();


public void SetValue(string tag, out point)
{
dic.TryGetValue(tag, out point);
point.totalCalls= 1;
//dic[tag] = point;   // 전체 복사 아니라면 dictionary 내에 값은 변경됨.
}
}

댓글

이 블로그의 인기 게시물

고유가 자동차 5부제 2부제 기상천외 에피소드

야구 WBC 한국 대표팀 외국계 선수 출전 가능한 이유 (혈통 규정 완벽 정리)

대기업 프론트엔드(frontend) 프레임워크 성향