Skip to content

Instantly share code, notes, and snippets.

@MikeMKH
Created January 4, 2017 12:40
Show Gist options
  • Select an option

  • Save MikeMKH/b5773170af92fab0d32fed8524137e77 to your computer and use it in GitHub Desktop.

Select an option

Save MikeMKH/b5773170af92fab0d32fed8524137e77 to your computer and use it in GitHub Desktop.
FizzBuzz kata in C# using .Net Core with macOS
MacBook-Pro:~/Kata/netcore/hello$ dotnet run
Project hello (.NETCoreApp,Version=v1.1) will be compiled because inputs were modified
Compiling hello for .NETCoreApp,Version=v1.1
Compilation succeeded.
0 Warning(s)
0 Error(s)
Time elapsed 00:00:00.9231498
2 is 2
3 is Fizz
4 is 4
5 is Buzz
6 is Fizz
10 is Buzz
15 is FizzBuzz
45 is FizzBuzz
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.1": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
}
},
"imports": "dnxcore50"
}
}
}
using System;
using System.Collections.Generic;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var values = new List<int> { 2, 3, 4, 5, 6, 10, 15, 45 };
values.ForEach(value => Console.WriteLine($"{value} is {value.FizzBuzz()}"));
}
}
public static class Wrapper
{
public static string FizzBuzz(this int value)
{
var fizzy = value % 3 == 0;
var buzzy = value % 5 == 0;
if ( fizzy && buzzy) return "FizzBuzz";
if ( fizzy && !buzzy) return "Fizz";
if (!fizzy && buzzy) return "Buzz";
if (!fizzy && !buzzy) return value.ToString();
return "No idea how we got here";
}
}
}
@MikeMKH

MikeMKH commented Jan 4, 2017

Copy link
Copy Markdown
Author

Hello .Net Core on my Mac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment