
Class, Structure, and Interface Members | 475
C# to VB
Syntax
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Note that .NET supports both static (or shared) members (which apply to the
type as a whole, and typically do not require that an object of that type be instan-
tiated) and instance members (which apply only to an instance of that type).
Shared or static members are indicated by using the
static keyword in C#. For
example:
public static bool IsMnemonic(char charCode, string text);
The corresponding VB keyword is Shared. Hence, the FromResource method, when
converted to VB, has the following syntax:
Public Shared Function IsMnemonic(charCode As Char, text As String) _
As Boolean
Fields
A field is simply a constant or a variable that is exposed as a publicly accessible
member of a type. In C#, for example, the
Nowhere field of the DataGrid.
HitTestInfo
class has the syntax:
public static readonly DataGrid.HitTestInfo Nowhere;
Note that C# indicates the data type of a field before the name of the field. (For
C# data types and their VB equivalents, see Table 22-3.) Also note that fields are
most often read-only. Constant fields, in fact, are always read-only. As a result,
the use of the C#
readonly keyword and the VB ReadOnly keyword with fields is
quite common.
The syntax for the
Nowhere field in Visual Basic then becomes:
Public Shared ...