コード例 #1
0
ファイル: Program.cs プロジェクト: tyrgin/net-courses
        static void Main(string[] args)
        {
            var numberGenerator = new NumberGenerator();

            Console.WriteLine("Even:");
            numberGenerator.Subscribe((x) =>
            {
                numberGenerator.ShowNumber(x);
            }, new List <Func <int, bool> >()
            {
                (x) => { return(x % 2 == 0); }
            });

            Console.WriteLine("\nDivisible by 3:");
            numberGenerator.Subscribe((x) =>
            {
                numberGenerator.ShowNumber(x);
            }, new List <Func <int, bool> >()
            {
                (x) => { return(x % 3 == 0); }
            });

            Console.WriteLine("\nDivisible by 4 and 6:");
            numberGenerator.Subscribe((x) =>
            {
                numberGenerator.ShowNumber(x);
            }, new List <Func <int, bool> >()
            {
                (x) => { return(x % 4 == 0); },
                (x) => { return(x % 6 == 0); }
            });

            Console.ReadKey();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: tyrgin/net-courses
        static void Main(string[] args)
        {
            NumberGenerator numberGenerator = new NumberGenerator();

            numberGenerator.Subscribe(x => Console.WriteLine($"Client 1 got {x}"), null);
            numberGenerator.Subscribe(x => Console.WriteLine($"Client 2 got {x} because it's a multiple of 6"),
                                      new List <Func <int, bool> > {
                x => x % 2 == 0, x => x % 3 == 0
            });
            numberGenerator.Generate(15);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: tyrgin/net-courses
        static void Main(string[] args)
        {
            NumberGenerator ng = new NumberGenerator();

            ng.Subscribe(x => Console.WriteLine("Client1 got " + x), null);
            var filter = new List <Func <int, bool> >()
            {
                (x) => { return(x % 3 == 0); }, (x) => { return(x % 5 == 0); }
            };

            ng.Subscribe(x => Console.WriteLine("Client2: This number is a multiple of 15. That's why i got " + x), filter);
            ng.Generate(20);
            Console.ReadKey(true);
        }