I have a struct like this.
public struct MyStruct
{
public string name;
// other variables and stuff
public MyStruct(string name)
{
this.name = name;
}
}
I'm storing many, possibly hundreds or even thousands of those in a dictionary with their name
s as keys.
var myStructs = new Dictionary<string, MyStruct>();
myStructs.Add("Foo", new MyStruct("Foo"));
I don't always have access to the dictionary's keys (such as when retrieving values) so the names of the structs have to be defined in them.
My problem is, the structs can have different names than their keys in the dictionary. Is it an actual problem to have such a condition exist?
myStructs.Add("Bar", new MyStruct("Baz"));
This is a bit of off-topic on this question yet kind-of relevant to the problem above, but if the name of a struct under the key Foo
is changed, how would I update the key to the new name?
var temp = myStructs["Foo"];
temp.name = "Bar";
myStructs["Foo"] = temp;