最新版 |
編集中の文章 |
33行目: |
33行目: |
| } | | } |
| return 0; | | return 0; |
− | }
| |
− | </source>
| |
− |
| |
− | === C# ===
| |
− | [[C Sharp|C#]]での実装例。
| |
− | <source lang="csharp">
| |
− | using System;
| |
− | using System.Collections.Generic;
| |
− | using System.Linq;
| |
− |
| |
− | namespace FizzBuzz
| |
− | {
| |
− | class MainClass
| |
− | {
| |
− | public static void Main(string[] args)
| |
− | {
| |
− | Enumerable.Range(1, int.MaxValue).Select(
| |
− | n =>
| |
− | (n % 15 == 0) ? "FizzBuzz" :
| |
− | (n % 3 == 0) ? "Fizz" :
| |
− | (n % 5 == 0) ? "Buzz" :
| |
− | n.ToString())
| |
− | .ForEach(Console.WriteLine);
| |
− | }
| |
− | }
| |
− |
| |
− | static class IEnumerableExtensions
| |
− | {
| |
− | public static void ForEach<TSource>(this IEnumerable<TSource> source, Action<TSource> action)
| |
− | {
| |
− | foreach (var item in source)
| |
− | {
| |
− | action(item);
| |
− | }
| |
− | }
| |
− | }
| |
| } | | } |
| </source> | | </source> |