Skip to Content
Beginning ASP.NET 3.5: In C# and VB
book

Beginning ASP.NET 3.5: In C# and VB

by Imar Spaanjaars
March 2008
Intermediate to advanced content levelIntermediate to advanced
766 pages
21h 15m
English
Wrox
Content preview from Beginning ASP.NET 3.5: In C# and VB

A.5. Chapter 5

A.5.1.

A.5.1.1.
A.5.1.1.1. Exercise 1 solution

Both the Byte and the SByte data types are designed to hold small, numeric values. Both of them take up exactly the same amount of computer memory, so you're probably best off using the Byte data type. Because it doesn't allow you to store negative numbers, it's clear from the start that it can only contain a number between 0 and 255. However, it's much better not to store someone's age, but the date of birth instead. That way, you can always extract the age from the date of birth by comparing it with today's date, as demonstrated by the following example:

VB.NET

Dim albertsBirthday As DateTime = New DateTime(1879, 3, 14)
Dim age As Integer = DateTime.Now.Year - albertsBirthday.Year       ' displays 129 in 2008

C#

DateTime albertsBirthday = new DateTime(1879, 3, 14);
int age = DateTime.Now.Year - albertsBirthday.Year;                // displays 129 in 2008
A.5.1.1.2. Exercise 2 solution

This code looks a little tricky because it uses an expression and an assignment in one condensed line of code. Because of the order in which things are executed, the expression is evaluated first, followed by the assignment. In the original code, this means that ShoppingCart.Items.Count > 0 is evaluated first. This is an expression that checks if the Count property of the Items collection in the shopping cart is greater than zero. As you learned in this chapter, this results in a Boolean expression with either the value True or False. This Boolean ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning ASP.NET 4: in C# and VB

Beginning ASP.NET 4: in C# and VB

Imar Spaanjaars
Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Bill Evjen, Scott Hanselman, Devin Rader

Publisher Resources

ISBN: 9780470187593Purchase book