FizzBuzz one-liner in C#
hacking

FizzBuzz: _Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”. Reference_

Console.WriteLine(String.Join(Environment.NewLine, Enumerable.Range(1, 100)
    .Select(i => (i % 3 == 0) ? new { n = i, w = "Fizz" } : new { n = i, w = "" })
    .Select(o => (o.n % 5 == 0) ? new { n = o.n, w = o.w + "Buzz" } : o)
    .Select(o => o.w == "" ? o.n.ToString() : o.w)));

© 2017 knoone.info. All rights reserved.