Visual Basic 2005 Language Features Sample

To get samples and instructions for installing them, see the following:

  • Click Samples on the Visual Studio Help menu.

    For more information, see Locating Sample Files.

  • The most recent versions and the complete list of samples are available on the Visual Studio 2008 Samples Web site.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied to a folder under \Program Files\Visual Studio 9\Samples\. For Visual Studio Express Editions, all samples are located on the Internet.

To run this sample

  • Press F5.

Demonstrates

This sample demonstrates these language features:

  • Operator overloading   The ValidatedString class represents a string with custom validation. The & operator returns the concatenation of two ValidatedString objects.

  • Generics   The Pair class holds two values. When you declare an instance of the Pair class, you specify the types of the two values. The Match method tests to whether the pair types and values are the same.

  • Using   The Using Statement (Visual Basic) references a stream resource opened by a request from a Web client. The stream instance is disposed of automatically at the end of the Using block.

  • TryCast and IsNot   TryCast attempts to cast an object to a particular type and returns the converted value. If the cast fails then Nothing is returned. The IsNot operator is used to test the return result for Nothing.