List <T> - The correct collection to use for a large number of items?
Edit : Well, because it is clear that I am using the wrong approach with this, I will explain what I intended to do. The general intention is (as an exercise) to check all valid email addresses in accordance with the specification. This part was supposed to generate a part of the data set to test the algorithm.
As an exercise, I am writing a program that will generate all possible email addresses. This will remove 80 81 65 ≈ 1.4e122 possible items. I am currently using to store the generated items, but I understand that it has the maximum capacity . I guess the right solution will not include of of s. This is what I still have. List<T>Int32.MaxValueListListList
private void GenerateLocalPart()
{
List<string> validLocalSymbols = new List<string>()
{
".", "!", "#", "$", "%", "&", "*", "+", "-",
"/", "^", "_", "`", "{", "|", "}", "~", "\"",
};
List<string> validLocalNumbers = new List<string>()
{
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
};
List<string> validLocalLowercase = new List<string>()
{
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
"k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
"u", "v", "w", "x", "y", "z",
};
List<string> validLocalUppercase = new List<string>()
{
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z",
};
List<string> validLocalPartCharacters = new List<string>();
validLocalPartCharacters.AddRange(validLocalSymbols);
validLocalPartCharacters.AddRange(validLocalNumbers);
validLocalPartCharacters.AddRange(validLocalLowercase);
validLocalPartCharacters.AddRange(validLocalUppercase);
List<string> targetSequence = validLocalLowercase;
int lengthOfStringToGenerate = 5;
int numberOfDifferentSourceCharacters = targetSequence.Count;
List<List<string>> localPart = new List<List<string>>();
List<string> localPartSeed = new List<string>();
localPart.Add(localPartSeed);
foreach (string character in targetSequence)
localPartSeed.Add(character);
for (int i = 1; i < lengthOfStringToGenerate; i++)
{
List<string> bufferList = new List<string>();
localPart.Add(bufferList);
foreach (string lastListString in localPart[i - 1])
foreach (string character in targetSequence)
bufferList.Add(lastListString + character);
}
Console.WriteLine("Break here.");
}
lengthOfStringToGenerate- the maximum length of the lines (therefore, it generates all combinations from 1 to lengthOfStringToGenerate). localPartwill have an Listequivalent amount lengthOfStringToGenerate. Is there any other type of collection I should use? Is there any other general approach I should take?