QA


Q&A

Q1:

What is the difference between a subroutine and a function?

A1:

Subroutines and functions both are modularization control structures that can accept zero or more input parameters. However, a function returns a value, whereas a subroutine does not.

Q2:

What is the purpose of the Protected or Private keywords found at the beginning of subroutine and function definitions? Are they necessary? When I'm creating a subroutine or function, what should I be using?

A2:

In its simplest form, a subroutine merely spells out the subroutine's name and input parameters, whereas a function must include its name, input parameters, and return value. However, in addition to these bare minimum pieces of information, a number of additional keywords can, optionally, be included.

One such set of keywords is the access modifier keywords. These are the keywords that precede the keyword Sub or Function, and include these options: Private, Protected, Public, Friend, or Protected Friend. These access modifiers define how other classes and derived classes can use the subroutines and functions. The details aren't important for the code examples we'll be examining throughout this book. In fact, when entering your own methods, you can always use Private. You can opt to type in this access modifier explicitly or simply omit it because the default is Private. (Event handlers, however, must be Protected. Let Visual Web Developer create the event handlers for you and don't change their access modifiers.)

Q3:

When calling a function, must its return value be assigned to a variable?

A3:

Recall that functions always return a value. Typically, the return value of a function is either used in an expression or stored in a variable. However, it is not required that the return value of a function be used at all. Imagine that we had a function called SaveCustomerInformation(name, age ) that took as input parameters the name and age of the customer and saved this information in a database. The return value of this function might be a DateTime variable that indicated when the last time the customer's information was updated. In certain situations, we might not care about when the customer's information was last updated; all we want to do is update the customer's information. In such a case, we could call the function and just disregard its return value. This is accomplished by calling a function just like we would a subroutine, as follows:

SaveCustomerInformation("Scott", 24) 





Sams Teach Yourself ASP. NET 2.0 in 24 Hours, Complete Starter Kit
Sams Teach Yourself ASP.NET 2.0 in 24 Hours, Complete Starter Kit
ISBN: 0672327384
EAN: 2147483647
Year: 2004
Pages: 233

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