Workshop


Quiz

1.

What is the one mutable property of a variable, and how is it changed throughout the execution of the program?

2.

If you wanted a variable to store whole numbers with values from 0 up to a value no greater than 10,000, what data type should you use?

3.

Does the following code contain an implicit narrowing cast?

Dim a, b as Integer b = 10 a = b / 2 


4.

Does the following statement evaluate to true or False?

(4 / 3) = 1 


5.

Does the following statement evaluate to TRue or False?

CType(4 / 3, Integer) = 1 


Answers

1.

The value of a variable is the only mutable property; the name and data type are immutable. The value of a variable is changed via the assignment statement, which assigns a new value to a variable.

2.

You could use the Short data type, although in the examples throughout this book, the default integer data type used will be Integer.

3.

Yes. The / operator always produces a nonintegral result, so b / 2 will return the value 5.0. Because this value must be cast to an integer to be assigned to a, a narrowing cast must be performed. The cast is implicit because there is no CType() function call there explicitly indicating that a cast should occur.

4.

It evaluates to False. The division 4 / 3 will produce the value 1.3333333333..., which is not equal to 1.

5.

It evaluates to True. The division 4 / 3 will produce the value 1.3333333333..., but when this is cast to type Integer, the remainder will be truncated, resulting in the value 1. Because 1 = 1, this will return true.

Exercises

There are no exercises for this hour mainly because all that we know how to do in Visual Basic at this point is declare typed variables and assign the values of expressions to these variables.

In the next hour we will be covering Visual Basic control structures, which allows for code to be executed repeatedly or conditionally. After we have covered this material, we'll be able to examine a number of germane coding examples.




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