Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

ASP.NET 2.0 Everyday Apps For Dumies 2006 phần 6 docx
PREMIUM
Số trang
43
Kích thước
1.1 MB
Định dạng
PDF
Lượt xem
1837

ASP.NET 2.0 Everyday Apps For Dumies 2006 phần 6 docx

Nội dung xem thử

Mô tả chi tiết

Listing 6-13 (continued)

return _state;

}

set

{

_state = value;

}

}

public string ZipCode ➝9

{

get

{

return _zipCode;

}

set

{

_zipCode = value;

}

}

public string Email ➝10

{

get

{

return _email;

}

set

{

_email = value;

}

}

public string PhoneNumber ➝11

{

get

{

return _phoneNumber;

}

set

{

_phoneNumber = value;

}

}

}

The following paragraphs define each component of this class:

➝ 1 The class begins by defining private instance variables that are

used to hold the values associated with the class properties.

By convention, each of these variable names begins with an

196 Part III: Building E-Commerce Applications

12_597760 ch06.qxp 1/11/06 9:56 PM Page 196

underscore to indicate that it corresponds to a property with the

same name.

➝ 2 The default constructor creates a Customer object with default

values for each of its properties.

➝ 3 This constructor accepts arguments that initialize the customer

data. Notice that the assignment statements don’t directly assign

values to the instance variables of the class. Instead, they use the

properties to assign these values. That way, any validation rou￾tines written in the property setters will be used. (In this example,

none of the property setters have validation routines. Still, it’s a

good practice to follow just in case.)

➝ 4 The LastName property represents the customer’s last name. Its

get routine simply returns the value of the _lastName instance

variable, and its set routine simply sets the _lastName variable

to the value passed via the value argument.

➝ 5 The FirstName property represents the customer’s first name,

which is stored in the _firstName instance variable.

➝ 6 The Address property represents the customer’s address, stored

in the _address instance variable.

➝ 7 The City property represents the customer’s city, stored in the

_city instance variable.

➝ 8 The State property represents the customer’s state, stored in the

_state instance variable.

➝ 9 The ZipCode property represents the customer’s Zip code, stored

in the _zipCode instance variable.

➝ 10 The Email property represents the customer’s e-mail address,

stored in the _email instance variable.

➝ 11 The PhoneNumber property represents the customer’s phone

number, stored in the _phoneNumber instance variable.

Listing 6-14: The Customer class (VB version)

Imports Microsoft.VisualBasic

Public Class Customer

Private _lastName As String ➝1

Private _firstName As String

Private _address As String

Private _city As String

Private _state As String

Private _zipCode As String

Private _phoneNumber As String

(continued)

Chapter 6: Building a Shopping Cart Application 197

12_597760 ch06.qxp 1/11/06 9:56 PM Page 197

Listing 6-14 (continued)

Private _email As String

Public Sub New() ➝2

End Sub

Public Sub New(ByVal lastName As String, _ ➝3

ByVal firstName As String, _

ByVal address As String, _

ByVal city As String, _

ByVal state As String, _

ByVal zipCode As String, _

ByVal phoneNumber As String, _

ByVal email As String)

Me.LastName = lastName

Me.FirstName = firstName

Me.Address = address

Me.City = city

Me.State = state

Me.ZipCode = zipCode

Me.PhoneNumber = phoneNumber

Me.Email = email

End Sub

Public Property LastName() As String ➝4

Get

Return _lastName

End Get

Set(ByVal value As String)

_lastName = value

End Set

End Property

Public Property FirstName() As String ➝5

Get

Return _firstName

End Get

Set(ByVal value As String)

_firstName = value

End Set

End Property

Public Property Address() As String ➝6

Get

Return _address

End Get

Set(ByVal value As String)

_address = value

End Set

End Property

Public Property City() As String ➝7

Get

198 Part III: Building E-Commerce Applications

12_597760 ch06.qxp 1/11/06 9:56 PM Page 198

Return _city

End Get

Set(ByVal value As String)

_city = value

End Set

End Property

Public Property State() As String ➝8

Get

Return _state

End Get

Set(ByVal value As String)

_state = value

End Set

End Property

Public Property ZipCode() As String ➝9

Get

Return _zipCode

End Get

Set(ByVal value As String)

_zipCode = value

End Set

End Property

Public Property Email() As String ➝10

Get

Return _email

End Get

Set(ByVal value As String)

_email = value

End Set

End Property

Public Property PhoneNumber() As String ➝11

Get

Return _phoneNumber

End Get

Set(ByVal value As String)

_phoneNumber = value

End Set

End Property

End Class

Creating the ShoppingCart Class

The ShoppingCart class represents the user’s virtual shopping cart, as

described in detail earlier in this chapter (see Table 6-5). Now, Listing 6-15

presents the C# version of the ShoppingCart class, and the Visual Basic ver￾sion is shown in Listing 6-16.

Chapter 6: Building a Shopping Cart Application 199

12_597760 ch06.qxp 1/11/06 9:56 PM Page 199

Tải ngay đi em, còn do dự, trời tối mất!