Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于创建委托对象-C#_C#_Delegates - Fatal编程技术网

关于创建委托对象-C#

关于创建委托对象-C#,c#,delegates,C#,Delegates,我定义了一种委托类型,如: delegate void DrawShape(Brush aBrush,Rectangle aRect); 您能告诉我为什么以下创建委托对象的方法都是正确的吗 DrawShape DrawRectangleMethod = CreateGraphics().FillRectangle; DrawShape AnotherDrawRectangleMethod = new DrawShape(CreateGraphics().FillRectangle); 为什么

我定义了一种委托类型,如:

delegate void DrawShape(Brush aBrush,Rectangle aRect);
您能告诉我为什么以下创建委托对象的方法都是正确的吗

DrawShape DrawRectangleMethod = CreateGraphics().FillRectangle;
DrawShape AnotherDrawRectangleMethod = new DrawShape(CreateGraphics().FillRectangle);
为什么没有“新”的方法可以正确工作

DrawShape DrawRectangleMethod = CreateGraphics().FillRectangle;
由于C#2的隐式方法组转换是规范化的,所以这是可能的


由于C#2的隐式方法组转换是规范化的,所以这是可能的。

因为编译器会自动为您插入它。只是语法上的糖


只需查看Jons的章节
委托

,因为编译器会自动为您插入它。只是语法上的糖


只需看一看Jons在第章
Delegories

C#足够聪明,可以为您处理方法组。方法组是不带括号的方法名称;可能有许多具有不同签名的方法重载,但不带括号的“基”名称称为方法组。编译器将为您插入构造函数调用,允许您编写更简洁的代码行。

C#足够聪明,可以为您处理方法组。方法组是不带括号的方法名称;可能有许多具有不同签名的方法重载,但不带括号的“基”名称称为方法组。编译器将为您插入构造函数调用,允许您编写更简洁的代码行。

我认为编译器将两行解释为相同。我认为编译器将两行解释为相同。谢谢。在得到你的答案之前,我对方法小组知之甚少。谢谢。在得到你们的答案之前,我对方法组知之甚少。