What is the easiest way to fill in the blanks in a list of numbers?

I am having trouble explaining the question in one line for the title, but hopefully this description will provide you with enough information to fully understand my question:

I have several variables in a Word document. Each variable has Value, which is a number (starting from 0 to the number of variables). A is SortedDictionaryfilled with these variables, but it is possible that the variable was deleted earlier, so there is a “gap”, so to speak. Example:

5 Variables are added to SortedDictionary<int, string>, where the first number is this int, and the string matches the part stringin the SortedDictionary.

0 "name 1"
1 "name 2"
2 "name 3"

Now one of the variables is deleted, so the dictionary is populated as follows:

0 "name 1"
2 "name 3"

SortedDictionary , . , , index 2, index 1 , index 0 .

, , - DeleteVariable(), , (), , SortedDictionary , , ( ).

.

+5
1

. . , (, , list.RemoveAt(index)), "" , .

+7

All Articles