
478
|
Chapter 22: Converting from C# to VB Syntax
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
The corresponding VB syntax is:
Public Shared ReadOnly Property ProductName As String
Note that properties, like methods, can use the object-oriented modifiers listed in
Table 22-4.
Events
Events are declared in C# using the event keyword, which is followed by the dele-
gate type returned by the event and the name of the event. For example, the
Parse
event of the Binding class has the following syntax:
public event ConvertEventHandler Parse;
The equivalent VB syntax is:
Public Event Parse As ConvertEventHandler
In addition, the C# event and the VB Event keywords can be preceded by the
object modifiers listed in Table 22-4.
Delegates
The syntax for a delegate in C# closely follows the syntax for a method. The
delegate statement is followed by the delegate’s return type (or void, if there is
none) and the delegate name. This in turn is followed by the delegate’s parameter
list, in which each parameter takes the form:
<parameter_type> <parameter_name>
For example:
public delegate void DragEventHandler(
object sender,
DragEventArgs e);
In a VB Delegate statement, the Delegate keyword is followed by the Sub keyword
(if the delegate returns a void in C#) or the
Function keyword (if the delegate
returns some other value). For example, in VB, the
DragEventHandler ...