Here is my C# and .NET Core FizzBuzz program.
Prerequisites
The versions of the following items that I used are displayed in brackets.
- Install Visual Studio Code. (1.34)
- Install the .NET Core SDK. (2.2.300)
- Install the C# extension for Visual Studio Code (1.19.1)
FizzBuzz
Start Visual Studio Code, open the Integrated Terminal (CTRL + ‘ or View > Integrated Terminal) and create a new console app by typing:
dotnet new console
Add the code below to the Program.cs file
using System;
namespace CSharpFizzBuzz
{
class Program
{
static void Main(string[] args)
{
for (int i = 1; i <= 100; i++)
{
bool fizz = i % 3 == 0;
bool buzz = i % 5 == 0;
if (fizz == true && buzz == true)
{
Console.WriteLine("FizzBuzz");
}
else if (fizz == true)
{
Console.WriteLine("Fizz");
}
else if (buzz == true)
{
Console.WriteLine("Buzz");
}
else
{
Console.WriteLine(i);
}
}
Console.Read();
}
}
}
Run the program
dotnet run
Inspect the output.
The completed example can be found on GitHub