|
-
Dec 28th, 2003, 11:56 PM
#1
Events in C#, and Me from VB.NET
In VB.NET, you could go into the code view of a form and select which event you want to use for any object and it would insert the code for the function. In C#, it lists the members and it's functions/variables. While this is useful, how exactly do I use events? Do I have to guess at what they're called or something?
Also, in VB.NET I could use the Me namespace to do alot of different things. What would be the alternative to Me in C#? Or isn't their one?
-
Dec 29th, 2003, 12:17 AM
#2
Frenzied Member
i really think u should pick up a c# book
but here is your answers
in c# events are in the property box, click the lightening bolt to list all the events for an object
and in c#, me = this
this.Caption = "blah";
-
Dec 29th, 2003, 12:20 AM
#3
Thanks, I'll pick up a book eventually. I need to get the woman's car fixed I hit as well as my own before I start going out and spending money.

I should be able to get most of it from now on though. I can't believe I didn't think of this, I know C++ and C++ uses that. bah
-
Dec 29th, 2003, 02:07 PM
#4
yay gay
Unlike in VB.NET where an event is like just an event, in C# an event is just a function pointer so to manually declare an event just do:
this.<event> += new <delegate>(function_to_point);
\m/  \m/
-
Dec 29th, 2003, 03:06 PM
#5
Sleep mode
Originally posted by PT Exorcist
Unlike in VB.NET where an event is like just an event, in C# an event is just a function pointer so to manually declare an event just do:
this.<event> += new <delegate>(function_to_point);
Events in .NET work the same way in VB.NET and C# . Both are safepointers that encapsulate event handlers which in turn call them back . So they are exactly alike .
-
Dec 29th, 2003, 04:07 PM
#6
yay gay
What I've said is that VB.NET hides all of that.
I programmed in vb.net for some months and only when i came to C# I realised what events really were -- function pointers
\m/  \m/
-
Dec 29th, 2003, 04:26 PM
#7
Sleep mode
Originally posted by PT Exorcist
What I've said is that VB.NET hides all of that.
I programmed in vb.net for some months and only when i came to C# I realised what events really were -- function pointers
To some extent , this is true but when working with custome events , then you are working with delegates (pointers) and you can see that .
-
Dec 29th, 2003, 10:06 PM
#8
PowerPoster
Originally posted by Pirate
To some extent , this is true but when working with custome events , then you are working with delegates (pointers) and you can see that .
You are ALWAYS using delegates (which are function pointers). VB.Net will hide it for you by using the 'Handles' statement when you are dealing with controls and what not, but don't mistake this hidden functionality as different. Under the hood VB.Net is using delegates for you.
Delegates allow one event to call one or several methods (functions/subs if you are a vb person). This means it is basically a pointer holder. It will hold pointers to methods that subscribe to the event. When a control/object raises a event, the delegate will call each of the subscribed functions.
This is why you can subscribe/unsubscribe from a event during run time.
-
Dec 29th, 2003, 10:54 PM
#9
Frenzied Member
You can also use Delegates in VB.NET if you want to do things the hard way.
-
Dec 29th, 2003, 11:08 PM
#10
Sleep mode
Originally posted by hellswraith
You are ALWAYS using delegates (which are function pointers). VB.Net will hide it for you by using the 'Handles' statement when you are dealing with controls and what not, but don't mistake this hidden functionality as different. Under the hood VB.Net is using delegates for you.
Delegates allow one event to call one or several methods (functions/subs if you are a vb person). This means it is basically a pointer holder. It will hold pointers to methods that subscribe to the event. When a control/object raises a event, the delegate will call each of the subscribed functions.
This is why you can subscribe/unsubscribe from a event during run time.
This is what I'm saying . The difference between VB.NET and C# is the syntax (VB.NET uses Addressof + handler) but C# use +/- operators to subscribe/unsubscribe .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|