The question is :
How to generate a list of all possible 3-chars strings in c# ?
The question is :
How to generate a list of all possible 3-chars strings in c# ?
IEnumerable<string> GetAllStrings(params char[] inputCharacterSet) {
return from n in inputCharacterSet
from m in inputCharacterSet
from k in inputCharacterSet
select new string(new [] { n, m, k });
}
public IEnumerable<String> Get3CharStrings(char[] domain)
{
foreach(char a in domain)
foreach(char b in domain)
foreach(char c in domain)
yield return "" + a + b + c;
}
EDIT: This is actually quite a bit slower than the LINQ solution posted by Mehrdad, although most of the difference lies in the use of return "" + a + b + c
instead of return new string(new[] { a, b, c})
.
Actual statistics (26-character alphabet, 10k iterations:
Mehrdad's code: 72.983 seconds
My code: 127.205 seconds
My code with Mehrdad's return statement: 75.055 seconds