﻿namespace MulticastDelegates
{
    using System;

    public delegate int StringDelegate<T>(T value);

    public class Startup
    {
        public static void Main()
        {
            StringDelegate<string> d = Startup.PrintString;
            var instance = new Startup();

            d += PrintStringLength;
            d += delegate (string str)
            {
                Console.WriteLine($"Uppercase: {str.ToUpper()}");
                return 3;
            };

            var result = d("some string value");
            Console.WriteLine($"Returned result: {result}");

            Func<string, int> predefinedIntParse = int.Parse;
            var number = predefinedIntParse("10");
            Console.WriteLine(number);

            Action<object> predefinedAction = Console.WriteLine;
            predefinedAction(1000);
        }

        private static int PrintString(string str)
        {
            Console.WriteLine("Str: {0}", str);
            return 1;
        }

        private static int PrintStringLength(string value)
        {
            Console.WriteLine("Length: {0}", value.Length);
            return 2;
        }
    }
}
