X hits on this document

PDF document

“Beginning Visual C# 2005 Express Edition Video Series” - page 24 / 73





24 / 73

Visual Basic:

Public Property ElapsedMileage() as integer Get () ' You could do some validation ' or modification here return m_ElapsedMileage End Get

Set (ByVal Value as integer) ' You could do some validation ' or modification here if Value > 1000000 then m_ElapsedMileage = 1000000 else m ElapsedMileage = Value end if End Set End Property _

In this example, we chose to use a private field m_ElapsedMileage to store the parameter of the Set statement. However, we do a little due dilligence to make sure that someone didn't enter a bogus amount of miles. Then we use the m_ElapsedMileage again when someone calls the Property Get statement.

So now let’s see how these are used in code:

Visual Basic:

Dim myCar As Car

If myCar.ElapsedMileage = 0 Then myCar.ElapsedMileage = 10000000 End If

Yes, this code is correct. It is identical to the code we used to talk about Public Fields. You may wonder WHERE the call to the Get and Set statements is located. Actually, the calls are implied by the fact that we are reading the value in the “if ... then” statement, and the fact that we are assigning it a value in the myCar.ElapsedMileage = 10000000 statement.

Supplemental Readings for the Express Edition Videos Copyright © 2005 LearnVisualStudio.NET


Document info
Document views216
Page views216
Page last viewedMon Jan 16 12:59:24 UTC 2017