Inconsistent Dictionary
Rai-a opened this issue · 1 comments
Rai-a commented
using System;
using System.Collections.Generic;
public class Class1
{
public static void Main(string[] args)
{
Dictionary<Class1, Class1> state1 = new Dictionary<Class1, Class1>();
state1.Add(new Class1(), new Class1());
foreach (Class1 key in state1.Keys)
Console.Write(state1[key]);
Dictionary<Class1, Class1> state2 = state1.Copy();
foreach (Class1 key in state2.Keys)
Console.Write(state2[key]);//Exception
}
}
Occurs for all Dictionarys who use classes as key that do not override GetHashCode()
jpmikkers commented
This is a tricky one, the only way to solve this is by filling a new Dictionary with the cloned keys and values.