
Class, Structure, and Interface Members | 477
C# to VB
Syntax
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
VB allows methods to be called using either named or positional
parameters. If named parameters are used, the parameter name
must correspond to that shown in the documentation. For instance,
Color.FromArgb can be called as follows using named parameters:
NewColor = Color.FromArgb(blue:=125, _
red:=125,
green:=125)
C# also uses a number of object-oriented qualifiers with methods. These, and
their VB equivalents, are shown in Table 22-4.
In both C# and VB, constructors have a special syntax. In C#, constructors have
the same name as the classes whose objects they instantiate and do not indicate a
return value. For example, the constructor for the
Button class is:
public Button( );
In VB, the constructor is represented by a call to a class’s New subprocedure. The
equivalent call to the
Button class constructor in VB is:
Public Sub New( )
Properties
The FileDialog.Title property provides a more or less typical example of a prop-
erty definition using C# syntax:
public string Title {get; set;}
Like all C# type definitions, the property’s data type precedes the property name.
The get; and set; property accessors indicate that this is a read-write property.
Read-only properties are indicated with a
get; only, while write-only properties
are ...