为什么一个事件的访问修饰符在默认情况下保护? [英] why is the access modifier of an event is protected by default?

查看:98
本文介绍了为什么一个事件的访问修饰符在默认情况下保护?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

保护无效ButtonSheel_Click(对象发件人,EventArgs五)

protected void ButtonSheel_Click(object sender, EventArgs e)

推荐答案

标记起来用于(在运行时)定义一个类继承自你的code定义背后的类(你可以看到在 @Page 的声明,我们定义页面所继承什么类)

The mark up is used (at runtime) to define a class which inherits from the class defined in your code behind (you can see this in the @Page declaration where we define what class the page inherits from)

<%@ Page Inherits="_Default" ...

这个类必须能够访问你定义要为你的控件的事件处理程序(单击按钮等),所以他们需要被标记为至少保护(而不是私人),以允许这些方法的方法继承的标记类的访问。

This class needs access to the methods that you define to be the event handlers for your controls (button clicks etc...), and so these methods they need to be marked as at least protected (rather than private) to allow the inheriting markup class access.

这篇关于为什么一个事件的访问修饰符在默认情况下保护?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆