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 내에 값은 변경됨.
}
}

댓글

이 블로그의 인기 게시물