Declaring Methods

The simple HelloWorld component in Listing 17.1 contains a single method named SayMessage(), which returns a string value. When writing components with Visual Basic .NET, you create methods by creating either a subroutine or a function. Use a subroutine when a method does not return a value, and use a function when a method does return a value.

The SayMessage() method in Listing 17.1 is an instance method. In other words, you must create a new instance of the HelloWorld class before you can call the SayMessage() method like this:

HelloWorld objHelloWorld = new HelloWorld();lblMessage.Text = objHelloWorld.SayMessage();

In the first line, a new instance of the HelloWorld component is created. The SayMessage() method is called ...

Get ASP.NET 4 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.