求解释,关于events的两句英文

JiangXiang 2013-01-01 01:49:18
在学习events,看到了两句英文,不知道是什么含义,请大家指点。谢谢

Events are properties of the class publishing the event.

The keyword event controls how the event property is accessed by the subscribing classes.
...全文
352 12 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
JiangXiang 2013-01-02
  • 打赏
  • 举报
回复
Conventions The following important conventions are used with events: Event Handlers in the .NET Framework return void and take two parameters. The first paramter is the source of the event; that is the publishing object. The second parameter is an object derived from EventArgs. Events are properties of the class publishing the event. The keyword event controls how the event property is accessed by the subscribing classes.
JiangXiang 2013-01-02
  • 打赏
  • 举报
回复
我的引用出自: http://www.akadia.com/services/dotnet_delegates_and_events.html
JiangXiang 2013-01-02
  • 打赏
  • 举报
回复
引用 7 楼 sp1234 的回复:
如果你从.net的角度,那么event是event,proproty是property,它们不是一类东西。因为具体的语言的设计是比较细致的(甚至是不一致的)。 但是如果你从面向对象设计角度,一个对象封装不过是“类名、属性、方法”三个东西,于是它把事件定义归入属性,以便于进一步理解在设计中的关系。 要理解自然语言、背景知识是需要一些经验的。
引用 8 楼 sp1234 的回复:
引用 6 楼 johnpher 的回复:感谢Jasondct和caozhy的耐心解答。 关于第二句的含义我还有些疑问。 The keyword event controls how the event property is accessed by the subscribing classes. 请问这种访问控制指的是什么? 是指 add { click……
感谢您的回答,解释得很清楚。谢谢
  • 打赏
  • 举报
回复
嗯,修改一下
public Action<string> Hello{get; set;}
这样好更像是“属性”了!呵呵 其实看你引用的这个作者的话,他就对property、event、field并没有先做特别的区分。可见他是站在面面对想编程语言的基本的通用概念上来讲的,而不是一上来就死抠“.net字眼”。当然,不理解很多作者这个背景,就会产生一些歧义。
  • 打赏
  • 举报
回复
引用 6 楼 johnpher 的回复:
感谢Jasondct和caozhy的耐心解答。 关于第二句的含义我还有些疑问。 The keyword event controls how the event property is accessed by the subscribing classes. 请问这种访问控制指的是什么? 是指 add { click += value; } remove ……
如果真的你去声明一个属性,例如写
public Action<string> Hello;
这就跟
public event Action<string> Hello;
有所对比。你可以试试看,前者,客户程序可以随意重新给Hello属性赋值、修改它。而后者,c#编译器约束客户程序只能用+=、-=等有限的三四个方法来操作它,通过对开发人员使用event的更深刻理解,语言设计者希望在编译时就把很多设计bug给挑出来(而不是像javascript之类的混乱的语言,等到程序运行到某一种特殊数据时,才在用户面前崩溃)。
  • 打赏
  • 举报
回复
如果你从.net的角度,那么event是event,proproty是property,它们不是一类东西。因为具体的语言的设计是比较细致的(甚至是不一致的)。 但是如果你从面向对象设计角度,一个对象封装不过是“类名、属性、方法”三个东西,于是它把事件定义归入属性,以便于进一步理解在设计中的关系。 要理解自然语言、背景知识是需要一些经验的。
JiangXiang 2013-01-02
  • 打赏
  • 举报
回复
感谢Jasondct和caozhy的耐心解答。 关于第二句的含义我还有些疑问。 The keyword event controls how the event property is accessed by the subscribing classes. 请问这种访问控制指的是什么? 是指 add { click += value; } remove { click -= value; } 吗?
JiangXiang 2013-01-02
  • 打赏
  • 举报
回复
引用 1 楼 BohemianLife 的回复:
google 一下就知道了
引用 3 楼 ITbailei 的回复:
引用 楼主 johnpher 的回复:在学习events,看到了两句英文,不知道是什么含义,请大家指点。谢谢 Events are properties of the class publishing the event. The keyword event controls how the event property is accessed by the ……
小弟不懂的不是单词
threenewbee 2013-01-01
  • 打赏
  • 举报
回复
Events are properties of the class publishing the event. Event是类发布的事件类型的属性。 The keyword event controls how the event property is accessed by the subscribing classes. event关键字控制事件属性如何被订阅的类访问。 简单来说是这个意思。属性你明白么,比如 private int x; public int X { get { return x; } set { x = value; } } 这里属性访问器X控制外部调用者如何访问私有字段x的方式。 那么事件是这样的特殊的属性 private event EventHandler click; public event EventHandler Click { add { click += value; } remove { click -= value; } } click是一个属性成员,你可以使用Click去控制如何添加/删除一个来自订阅者的事件处理。
dali_yan 2013-01-01
  • 打赏
  • 举报
回复
引用 楼主 johnpher 的回复:
在学习events,看到了两句英文,不知道是什么含义,请大家指点。谢谢 Events are properties of the class publishing the event. The keyword event controls how the event property is accessed by the subscribing classes……
有道,谷歌,百度为啥一句英文也要问呢?
段传涛 2013-01-01
  • 打赏
  • 举报
回复
Google出的不对 Events are properties of the class publishing the event. 要发布的这个事件,是类的属性 The keyword event controls how the event property is accessed by the subscribing classes. 关键事件控制的事件属性是如何被引用类访问。
波西米亚人生 2013-01-01
  • 打赏
  • 举报
回复
google 一下就知道了

111,088

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧