- Home /
C# Auto Generated Key with Variable (Hash, Metadata, etc.)
Hi everyone!
Today's question is regarding variables. I want to store variables inside a dictonary and the key to recover the variables' value should be auto generated. Best would be a construct with classname+variablename, since I need them unique.
Thx! Cheers Phoenix
Answer by Sundar · Aug 14, 2012 at 06:21 PM
Use Guid
Dictionary<Guid, myVariable> storeVariable = new Dictionary< Guid, myVariable>();
Guid aKey = Guid.NewGuid();
myVariable mine = value;
storeVariable.Add( aKey, mine );
or
storeVariable.Add( Guid.NewGuid(), mine );
Answer by Ravart · Aug 14, 2012 at 11:44 PM
Guid sounds not bad but i have to generate the key with the variable, since the key itself is not saved, means I need to generate the same key on the fly.
Your answer
Follow this Question
Related Questions
How can I set a dictionary value in foreach loop? 1 Answer
why isn't my lock working 1 Answer
Generic dictionary emptying itself? 0 Answers
Field Initializer Error 1 Answer
Getting the sum of random values in the dictionary 2 Answers