예제 #1
0
        static void Main(string[] args)
        {
            delegate1 dl1 = new delegate1(add);

            dl1 += new delegate1(sub);                  //多播委托。
            Console.WriteLine("1+3={0}", dl1(1, 3));
            Console.WriteLine("3-1={0}", dl1(3, 1));    //由于委托的顺序不确定,造成输出错误
            foreach (var dl in dl1.GetInvocationList()) //循环多播委托的方法
            {
                Console.WriteLine("1,3={0}", (dl as delegate1)(3, 1));
            }
            Func <int, int, int> dl2 = delegate(int a, int b)   //匿名方法。单行定义委托,有返回值
            {
                return(a + b);
            };

            Console.WriteLine("2+4={0}", dl2(2, 4));
            Action <string> dl3 = str => //无返回值委托,lambda表达式
            {
                Console.WriteLine(str += "!");
            };

            dl3("hello world");


            Console.ReadKey();
        }
예제 #2
0
        static void Main(string[] args)
        {
            string    str        = Console.ReadLine();
            int       a          = Convert.ToInt32(Console.ReadLine());
            delegate1 mydelegate = method1;

            mydelegate(a, str);

            Console.WriteLine("----------------- Секция обычных делегатов ------------------");

            method2(a, str, mydelegate);

            Console.WriteLine("-----------------------------------");

            delegate1 delegate2 = (x, y) => y + " " + x.ToString();

            Console.WriteLine(delegate2(a, str));

            Console.WriteLine("------------- Секция Action -------------");

            Action <int, string> action_delegate  = (x, y) => Console.WriteLine(x.ToString() + " " + str);
            Action <int, string> action_delegate2 = method3;

            action_delegate(a, str);
            action_delegate2(a, str);

            Console.WriteLine("------------------- Секция Func ----------------------");

            Func <int, string, string> funcdelegat = method1;

            method_func(str, a, funcdelegat);
        }
예제 #3
0
        static void Main(string[] args)
        {
            delegate1 anonim     = (a, b, c) => { return((a + b + c) / 3); };
            delegate1 MyDelegate = new delegate1(anonim);

            Console.WriteLine(MyDelegate.Invoke(3, 4, 5));
            Console.ReadKey();
        }
예제 #4
0
        }    /// <summary>

        /// this deals with creation of objects and displaying.
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            Delegatedemo obj  = new Delegatedemo();
            delegate1    del  = new delegate1(obj.add);
            delegate1    del1 = new delegate1(obj.sub);

            del(1, 2);
            del1(2, 1);
        }
예제 #5
0
        public MainWindow()
        {
            InitializeComponent();
            serialPort              = new SerialPort();
            serialPort.ReadTimeout  = 500;
            serialPort.WriteTimeout = 500;



            serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
            mydelegate = new delegate1(displayReceived);
        }
        static void Main(string[] args)
        {
            deleGate3 ddd = d3;

            ddd("hej", "med", "dig");
            delegate1 dd = d1;

            dd();
            deleGate2 d2 = f1;

            Console.WriteLine(d2());
            Console.ReadLine();
        }
예제 #7
0
    void Start()
    {
        delegate1 d1 = new delegate1(show);

        d1 += new delegate1(hoge);
        d1 += new delegate1(fuga);
        d1();

        delegate2 d2 = new delegate2(piyo);

        print(d2(2, 10));

        //いままで 
        delegate3 d3 = new delegate3(ShowShow);

        d3(5);

        //匿名メソッド
        delegate3 d3s = delegate(int i){ print(i); };

        d3s(10);

        delegate3 d3ss = delegate(int i)
        {
            if (i > 10)
            {
                print("10より大きいです");
            }
            else
            {
                print("10以下です");
            }
        };

        d3ss(36);


        delegate6 d6 = () => { show(); };

        d6();
        delegate7 d7 = (x) => { return(ShowShowShow(x)); };

        d7(3);
    }
예제 #8
0
        public IActionResult Index()
        {
            string[] words = StartDate.Split('/');

            string day   = words[0];
            string month = words[1];
            string year  = words[2];

            int passedMonth = (DateTime.Now.Year - Convert.ToInt32(year)) * 12 + Convert.ToInt32(month);//şu ana kadar geçen ay
            int passedYear  = passedMonth / 12;

            int femaleAdultAnimalNumber = 1;

            List <ResultViewModel> results = new List <ResultViewModel>();

            //her gebelik bir thread
            while (currentMonth <= passedMonth)
            {
                //doğum yapabilir durumdaki dişilerin sayısı kadar thread yarat
                for (int i = 1; i <= femaleAdultAnimalNumber; i++)
                {
                    doit += new delegate1(GiveBirth);
                    femaleAnimalNumber = femaleAnimalNumber + Convert.ToInt32(FemaleNumberOfPuppies);
                    maleAnimalNumber   = maleAnimalNumber + Convert.ToInt32(MaleNumberOfPuppies);
                }

                femaleAdultAnimalNumber = femaleAnimalNumber; //doğumdan sonra her dişi birey erişkinliğe ulaşınca femaleAdultAnimalNumber sayısını arttırmak gerek.
                                                              // ama bunu hesaplayamadım


                ResultViewModel resultViewModel = new ResultViewModel()
                {
                    NumberOfFemale = femaleAnimalNumber,
                    NumberOfMale   = maleAnimalNumber,
                    NumberOfMonth  = currentMonth
                };

                currentMonth++;
                results.Add(resultViewModel);
            }

            return(View("Index", results));
        }
예제 #9
0
        static void Main(string[] args)
        {
            delegate1 delegate1 = new delegate1(random);
            delegate1 delegate2 = new delegate1(random);

            delegate1[] array = { delegate1, delegate2 };

            Anonim anonim = (array) =>
            {
                int count = 0;
                int sum   = 0;
                foreach (delegate1 item in array)
                {
                    sum += item.Invoke();
                    count++;
                }
                return(sum / count);
            };

            Console.WriteLine(anonim.Invoke(array));
        }
예제 #10
0
 public static void method2(int a, string str1, delegate1 mydeleg)
 {
     mydeleg(a, str1);
 }
예제 #11
0
        // BackgroundWorker for show reflaction button.
        private void BwReflactionButton_DoWork(object sender, DoWorkEventArgs e)
        {
            delegate1 del = new delegate1(ShowReclactionButton);

            Btn_reflection.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, del);
        }
예제 #12
0
        // BackgroundWorker for progress bar update.
        private void BwProgressBarUpdate_DoWork(object sender, DoWorkEventArgs e)
        {
            delegate1 del = new delegate1(UpdateDataGrid);

            download_DataGrid.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, del);
        }
 static FileParser()
 {
     customParsingCallbacks["points"] = new delegate1(geometryContentParser);
     customParsingCallbacks["period"] = new delegate2(function2);
 }
예제 #14
0
        // Append message to Log in the background.
        private void Bw_DoWork(object sender, DoWorkEventArgs e)
        {
            delegate1 delegate1 = new delegate1(WriteToLog);

            TextBox_serverLog.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, delegate1, e.Argument.ToString());
        }