쉽게 말해서
{
Dictionary< List<int>, List<int> > myDic = new Dictionary< List<int>, List<int> >();
List<int> front = new List<int>();
List<int> behind = new List<int>();
}
라고 선언을 했고
{
myDic.Add( front, behind );
}
이런 형태를 만들어 쓰고 싶음
문제는 뭐냐면
{
front.Add( 0 );
front.Add( 1 );
behind.Add( 9 );
behind.Add( 8 );
myDic.Add( front, behind );
Debug.Log( myDic[ front ][0] ); // 결과 : 9
front[ 0 ] = 2;
front[ 1 ] = 3;
Debug.Log( myDic[ front ][0] ); // 예상 결과 : 오류, 실제 결과 : 9
}
front 내부 값이 변경되었지만 그게 반영이 안되는 것 같음
C++ 의 map 으로 비슷한 기능을 만들 수 있었지만 C# 으로 그대로 옮겨 적었더니 이렇게 되었음
내가 해본 방법은
{
myDic.Add( front.ConvertAll(o => (int)o),behind ); // Deep copy?
myDic.Add( new List<int>() { 2, 3 }, behind ); // value only List?
}
이렇게 시도해 보았지만 원하는 결과를 얻을 수 없었음
더 좋은 방법이 있을까?