C#C
C#4y ago
Turwaith

FizzBuzz as short as possible

With a little help from StackOverflow I came up with this:

List<string> testList = new List<string>();
testList.Add(Enumerable.Range(1, 200)
                    .Select(n => n % 15 == 0 ? "FizzBuzz"
                               : n % 3 == 0 ? "Fizz"
                               : n % 5 == 0 ? "Buzz"
                               : n.ToString()).ToString());

Now it adds only one element though, which is "System.Linq.Enumerable+SelectRangeIterator'1[System.String]". How do I get this expression to have one list object for each number?
Was this page helpful?