I have a list of items and will insert them into a dictionary but must determine keys. For my purposes, the characters that these keys consist of is in the following array:
char[] keyChars = { '0', '1', 'A', 'B' };
Keys can be varying length.
For example, if length is 2, the first key would be 00 and the last would be BB (assuming I need all of them, probably not in most cases).
However, I'm not sure if I've fried my brain or what, but I cannot figure out how to generate this range of keys.
I have the following skeleton build but haven't been able to figure out what to put in it...
//These below 2 are determined at runtime and may vary (hardcoded for example's sake)
int count = 8; // Number of keys I need to generate
int length = 3; //Length the key need to be
char[] keyChars = { '0', '1', 'A', 'B' };
List<string> keys = new List<string>();
char[] result;
for (int i = 0; i < count; i++)
{
result = new char[length];
for (int j = length - 1; j >= 0; j--)
{
result[j] = keyChars[/*what should go here?*/];
}
keys.Add(new string(result));
}
The only thing I'm fairly certain I need is a <something> % keyChars.Length
so that I can stay in bounds of the array. But my math knowledge is proving a little rusty at the moment and it's taking me far longer than it should..