Skip to content

Instantly share code, notes, and snippets.

@emadb emadb/fizzbuzz.cs
Created Nov 7, 2019

Embed
What would you like to do?
Fizzbuzz
using System;
using System.Linq;
using System.Collections.Generic;
namespace CodicePlastico
{
public class FizzBuzz
{
private static readonly IDictionary<int, string> _cases = new Dictionary<int, string>
{
{3, "fizz"},
{5, "buzz"}
};
public static string Play(int n)
{
var result = _cases
.Where(x => n % x.Key == 0) .Aggregate("", (c, a) => c + a.Value);
return string.IsNullOrEmpty(result) ? n.ToString() : result;
}
public static void Main()
{
for(int i=1;i<=100;i++)
{
Console.WriteLine(Play(i));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.