Created
November 19, 2020 15:30
-
-
Save buvinghausen/95f30490ed5adff510a02f108703d871 to your computer and use it in GitHub Desktop.
FizzBuzz using C# pattern matching, value tuples, and a switch expression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
static List<string> FizzBuzz(int count) => Enumerable | |
.Range(1, count) | |
.Select(i => (i % 3 == 0, i % 5 == 0) switch | |
{ | |
(true, false) => "Fizz", | |
(false, true) => "Buzz", | |
(true, true) => "FizzBuzz", | |
_ => $"{i}" | |
}) | |
.ToList(); | |
FizzBuzz(63).ForEach(Console.WriteLine); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment