-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFizzBuzz.cs
More file actions
23 lines (23 loc) · 712 Bytes
/
FizzBuzz.cs
File metadata and controls
23 lines (23 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class Solution
{
private bool IsDivisibleBy (int dividend, int divisor)
{
return dividend % divisor == 0;
}
public IList<string> FizzBuzz(int n)
{
List<string> lista = new List<string>();
for (int i = 1; i <= n; i++)
{
string result= i switch
{
_ when IsDivisibleBy(dividend: i, divisor: 3) && IsDivisibleBy(dividend: i, divisor: 5) => "FizzBuzz",
_ when IsDivisibleBy(dividend: i, divisor: 3) => "Fizz",
_ when IsDivisibleBy(dividend: i, divisor: 5) => "Buzz",
_ => i.ToString()
};
lista.Add(result);
}
return lista;
}
}