3.1 Member Variables

only for RuBoard

3.1 Member Variables

As shown in Example 3-1, member variables of a class are typically declared at the top of the class block (with or without an initial state).

The term "member variables" also includes constants and enumerations. By default, constants and enumerations are shared, so an instance of the class is not necessary; these values pertain to every instance of an object. Constants can refer to any data type, while enumerations are restricted to Byte , Short , Integer , and Long . Example 3-2 illustrates the definition of member variables in a class.

Example 3-2. Member variables
 Public Class World         'Member data represents state     Private age As Double         'Constants     Public Const AverageDensity As Single = 5515  '(kg/m3)     Public Const PolarRadius = 6356.8             'In km     Public Const SatelliteCount As Byte = 1       'The Moon         'Enums     Public Enum Continents         Africa = 1         Antarctica = 2         Asia = 3         Australia = 4         Europe = 5         NorthAmerica = 6         SouthAmerica = 7     End Enum         Public Shared Sub Hello( )         Console.WriteLine("Hello, World!")     End Sub     End Class 

Variable Names

When naming classes or constant values, by convention PascalCasing should be used. With PascalCasing , each word comprising the variable name should start with an uppercase letter. Conversely, instance variables use camelCasing , which always makes the first word lowercase.

In all cases, Hungarian notation is avoided. Rather than naming your variables based on a type, you should use a meaningful name instead. The .NET Framework Design Guidelines contains a complete description of the naming conventions used within the framework.

Many of you will no doubt give up on using Hungarian notation when it's pried from your cold, dead fingers (regardless of what some specification has to say about it). How about a compromise? Try to use it only internally and make your public interfaces follow convention. Think about how your public interfaces look to the people who use your code. The era of IntelliSense has arrived!

VB.NET also supports named arguments, which means you can refer to a parameter during the method call. Which is easier to remember?

 car.Display(Name:="Rolls-Royce") 

or

 car.Display(strCarName:="Bentley") 
only for RuBoard


Object-Oriented Programming with Visual Basic. Net
Object-Oriented Programming with Visual Basic .NET
ISBN: 0596001460
EAN: 2147483647
Year: 2001
Pages: 112
Authors: J.P. Hamilton

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net