Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Edit 2</strong>: </p> <p><strong>This is probably the easiest way to implement it</strong>. I tested it, it works fine. You could generate a infinite number of strings.</p> <pre><code>public IEnumerable&lt;string&gt; GenerateStrings() { foreach(string character in Alphabet()) { yield return character; } foreach (string prefix in GenerateStrings()) { foreach(string suffix in Alphabet()) { yield return prefix + suffix; } } } public IEnumerable&lt;string&gt; Alphabet() { for(int i = 0; i &lt; 26; i++) { yield return ((char)('A' + i)).ToString(); } } </code></pre> <hr> <p>Stuff I wrote before:</p> <p>You could also write a little recursive function which returns any string by a certain index. This may not be optimal performance wise, because there are some repetitive divisions, but it may be fast enough for your purpose. </p> <p>It is quite short and easy:</p> <pre><code>string GetString(int index) { if (index &lt; 26) { return ((char)('A' + index)).ToString(); } return GetString(index / 26 - 1) + GetString(index % 26); } </code></pre> <p>usage (may also be put into another method:</p> <pre><code>List&lt;string&gt; strings = Enumerable.Range(0, 1000) .Select(x =&gt; GetString(x)) .ToList(); </code></pre> <p>This is working code, just wrote a test for it.</p> <hr> <p><strong>Edit:</strong> eg, the "full linq way" application of GetString:</p> <pre><code>public void IEnumerale&lt;string&gt; GenerateStrings() { int index = 0; // generate "infinit" number of values ... while (true) { // ignoring index == int.MaxValue yield return GetString(index++); } } List&lt;string&gt; strings = GenerateStrings().Take(1000).ToList(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload