FizzBuzz one-liner in C#

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)));

2 thoughts on “FizzBuzz one-liner in C#”

  1. Oh my goodness! Awesome article dude! Thank you, However I am going through troubles with
    your RSS. I don’t know why I can’t join it. Is there anybody else having similar RSS issues?
    Anyone who knows the answer will you kindly respond? Thanks!
    !

Leave a Reply

Your email address will not be published. Required fields are marked *

*