I am making application in C#. In my application I am using Dictionary of following structure:
Dictionary<int, string> DataDictionary1 = new Dictionary<int, string>();
Here I want the key value in dictionary should be auto increment. For that I am using logic as:
string header="ABC";
int maxKey = DataDictionary1 .Max(x => x.Key);
DataDictionary1 .Add(maxKey + 1, header);
Is that a efficient way because I want to do this operation continuously. Is there any other way which is faster than this way?
Why don’y you just use a
List<string>and then add elements to it. The index of the element in the list will represent the Key. So:and then: