English 中文(简体)
采用事件类型构造的目的/推论
原标题:What the purpose/difference in using an event-type constructor
  • 时间:2010-06-07 22:19:02
  •  标签:
  • c#
  • events

在我能够发现的所有例子中,以及自动生成的“视力演播室”密码,活动采用以下代码:

button1.Click += new System.EventHandler(this.button1_Click);

但是,我也可以通过om断建筑设计师的包裹来写明它:

button1.Click += this.button1_Click;

后者还汇编罚款。

What is the difference between these two? And why is the first one mostly used/preferred?

最佳回答

第二种形式(从method group改为代表型)在C# 2之前就得到了支持,因此,2005年之前撰写的任何辅导等都将采用第一种形式。

此外,国际红十字与红新月联会视频演播室自动完成了第一种形式。 我个人喜欢第二种。

问题回答

第二种是合成糖,通过编织家的魔术,扩大至头一种。

第一种可能更可取,因为事件类型从法典中隐蔽,因此可能更容易读到,但功能上(和IL-wise)则照搬。

正在拆除激励食糖的活动处理器:

 button1.Click -= new System.EventHandler(this.button1_Click);

使用new至remove 是的。

即便是全权建筑群也是糖。 代表需要一种办法和目标。 这一目标是自动确定的,没有具体说明。 这将是“这”。 很不幸,它掩盖了这样一个事实,即订阅一项活动增加了提及贵阶层的物品,使其免遭垃圾的收集。 这一点在C++/CLI syntax中是明确的:

 button1->Click += gcnew System::EventHandler(this, &button1_Click);

有了有趣的扭曲,你实际上可以采用另一个物体或类别的活动处理方法。 这不是很多用途。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签