VB programmer's C # 3

zhaozj2021-02-08  200

Events in C # are the same as the events in VB. But in C #, any class can generate a set of events, and any object can be bundled with these events. The event in C # is based on delegates. When designing events, it is usually considered delegates to accept two parameters: the first parameter is an object that causes an event, and the second parameter is an object containing an event argument.

Now we define a delegates for an event. When there is a new email, this event will be activated:

=== DELEGATE declaration ==============

Pubic Delegate Void NewMaileventHandler (Object Sender, NewMaileventargs E);

=== Event declaration =============

Public Event NewMaileventrandler OnnewmailHandler;

Attributes

The attribute in the C # is the same as the properties in the VB. Please see an example of a simple attribute:

Class test

{

PRIVATE STRING NAME;

Public String Name;

{

get

{

Return Name

}

set

{

Name = value;

}

}

}

The GET method and SET method are so-called "Accessor" methods.

We can also use the Virtual, Override or Abstract modifiers to declare attributes. Now let's set the properties:

Test T = New Test ();

T.NAME = "this is the name"

As in VB, to establish a read-only attribute, you can omit "get". Note that attributes can be inherited.

转载请注明原文地址:https://www.9cbs.com/read-3272.html

New Post(0)