Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There's always the obligatory LINQ implementation. Most likely rubbish performance, but since when did performance get in the way of using cool new features?</p> <pre><code>var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); var sequence = from one in letters from two in letters from three in letters from four in letters orderby one, two, three, four select new string(new[] { one, two, three, four }); </code></pre> <p>'sequence' will now be an IQueryable that contains AAAA to ZZZZ.</p> <p>Edit:</p> <p>Ok, so it was bugging me that it should be possible to make a sequence of configurable length with a configurable alphabet using LINQ. So here it is. Again, completely pointless but it was bugging me.</p> <pre><code>public void Nonsense() { var letters = new[]{"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"}; foreach (var val in Sequence(letters, 4)) Console.WriteLine(val); } private IQueryable&lt;string&gt; Sequence(string[] alphabet, int size) { // create the first level var sequence = alphabet.AsQueryable(); // add each subsequent level for (var i = 1; i &lt; size; i++) sequence = AddLevel(sequence, alphabet); return from value in sequence orderby value select value; } private IQueryable&lt;string&gt; AddLevel(IQueryable&lt;string&gt; current, string[] characters) { return from one in current from character in characters select one + character; } </code></pre> <p>The call to the Sequence method produces the same AAAA to ZZZZ list as before but now you can change the dictionary used and how long the produced words will be.</p>
 

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