X hits on this document

PDF document

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

158 views

0 shares

0 downloads

0 comments

44 / 73

C#:

public int ElapsedMileage {

get {

// You could do some validation // or modification here return _elapsedMileage;

} set {

// You could do some validation // or modification here if (value > 1000000) {

elapsedValue = 1000000; } else { _

elapsedValue = value;

_

}

}

}

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

So now lets see how these are used in code:

C#:

Car myCar = new Car(); if (myCar.ElapsedMileage == 0) {

myCar.ElapsedMileage = 10000000; }

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



Document info
Document views158
Page views158
Page last viewedSun Dec 04 06:31:35 UTC 2016
Pages73
Paragraphs821
Words15988

Comments