注册 登录
编程论坛 C# 论坛

Action 委托创建委托实例和不创建委托实例调用方法的区别

平淡最真 发布于 2020-06-13 22:49, 1746 次点击
程序代码:
using System;
using System.Collections.Generic;
using System.Linq;

namespace PropertySample
{
    class Program
    {
        static void Main(string[] args)
        {
            Calculator calculator = new Calculator();
            Action action1 = calculator.Report;               //
            Action action2 = new Action(calculator.Report);   //
            action1();
            action2();
        }
    }

    class Calculator
    {
        public void Report()
        {
            Console.WriteLine("I have 3 methods.");
        }
    }
}

请教一下 程序中画下划线的两句程序都可以实现一样的委托效果,但是这两句有什么区别?感谢
1 回复
#2
a4725444362020-08-29 17:07
没区别!
1