473,749 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

purpose of 'event' keyword?

Bob

C# newbie here.... studying about delegates and now events.

I just don't get the purpose of declaring events using the event keyword.
What does this do for me that can't be done using only delegates?
Nov 15 '05 #1
3 2942
I had the same question a couple of month ago:

check (from post 3):
http://www.google.ch/groups?hl=en&lr...%26scoring%3Dd
José

"Bob" <i.************ *@spammers.suck .com> wrote in message
news:BC1FE189.7 F20C%i.******** *****@spammers. suck.com...

C# newbie here.... studying about delegates and now events.

I just don't get the purpose of declaring events using the event keyword.
What does this do for me that can't be done using only delegates?

Nov 15 '05 #2
Hi Bob,

Unlike delegates, with an event, you can only use += or -= to
add or remove event handlers. This ensures that the
existing list of delegates isn't inadvertently deleted by an
event subscriber using the = operator.

Another diffreence being that unlike plain delegates, only the
class that owns the event can invoke/fire the event to the
event handlers.

Regards,
Aravind C
"Bob" <i.************ *@spammers.suck .com> wrote in message
news:BC1FE189.7 F20C%i.******** *****@spammers. suck.com...

C# newbie here.... studying about delegates and now events.

I just don't get the purpose of declaring events using the event keyword.
What does this do for me that can't be done using only delegates?

Nov 15 '05 #3
Bob

Wow - what a great newsgroup. I got two questions answered within two hours
of posting.

Thanks for the link to the past thread, Jose.
On 1/6/04 5:17 AM, in article #Q************* *@TK2MSFTNGP10. phx.gbl,
"Aravind C" <ar***********@ nospam.hotmail. com> wrote:
Hi Bob,

Unlike delegates, with an event, you can only use += or -= to
add or remove event handlers. This ensures that the
existing list of delegates isn't inadvertently deleted by an
event subscriber using the = operator.

Another diffreence being that unlike plain delegates, only the
class that owns the event can invoke/fire the event to the
event handlers.

Regards,
Aravind C
"Bob" <i.************ *@spammers.suck .com> wrote in message
news:BC1FE189.7 F20C%i.******** *****@spammers. suck.com...

C# newbie here.... studying about delegates and now events.

I just don't get the purpose of declaring events using the event keyword.
What does this do for me that can't be done using only delegates?



Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4278
by: muser | last post by:
In Microsoft.NET there is an event keyword that allows event sources ( a button on a keyboard ) access event receivers ( such as a form or a file ). I would like to know if there is such a keyword present in Visual studio C++, and if so how it is implemented for opening and creating files.
3
1557
by: Mark Broadbent | last post by:
hi guys, i am currently studying through my book and wonder if somebody could clear this up before i have to look at other sources. I have code which defines and creates an event object using a delegate as the handler as thus.. //Start of code using System; // Declare a delegate for an event. delegate void MyEventHandler();
7
1980
by: Rakesh Rajan | last post by:
Hi, I find that when i define a delegate, it gets derived from MulticastDelegate, which provides all funtionality that events would provide (like registering new handlers etc.). Then, apart from being a bit more neater, could there have been any other reason that an 'event' keyword became necessary in C#? Thanks in advance, --
2
2067
by: Bae,Hyun-jik | last post by:
I am a newbie to C#. During studying 'event' keyword, I erased the keyword 'event' and found that its behavior doesn't change. For example: public event AlarmEventHandler Alarm; and public AlarmEventHandler Alarm;
3
1746
by: Arthur Dent | last post by:
Hi all, Im just curious, what is the purpose of the keyword "Overloads" in VB nowadays? I understand conceptually what overloads are and what they do, but im a little puzzled, because if you declare two subs or properties or functions with the same name but different signatures, it seems to overload them without any problem anyway, so why
7
1467
by: Bruce | last post by:
I have a DotNet C++ class that I would like to fire an event to then be used by VB.Net using the With Events keyword. I have experience creating connection point events for ActiveX controls, it is actually very easy with the ATL wizard but I am lost when it comes to C++ .Net's events. Can anyone please point me to an example in VC++ .Net that allows me to then use the component in VB with the With Events keyword?
2
2353
by: muler | last post by:
Hi all, I can't figure out why we need the 'event' keyword, because without having it I can accomplish the same thing. So, why do we need to put the event keyword? namespace DelegateEx { delegate void BeastCaptured(string msg); class A
1
4160
by: halekio | last post by:
Hi all, Please bear with me as I've only started programming in C# 2 weeks ago and this is my first contact with OOP. I ran into a situation where I needed to catch an event in an object that had no connection or reference to the object that triggered it. It goes something like this: (not syntactically correct..it's just for the idea)
4
9858
by: FullBandwidth | last post by:
I have been perusing various blogs and MSDN pages discussing the use of event properties and the EventHandlerList class. I don't believe there's anything special about the EventHandlerList class in this context, in fact some articles from pre-2.0 suggest using any collection class of your choice. So my questions focus more on the syntax of event properties provided by the "event" keyword in C#. (Disclaimer - I am a C++ programmer working...
0
8833
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9568
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6801
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4709
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4881
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3320
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2218
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.