X hits on this document

PDF document

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

145 views

0 shares

0 downloads

0 comments

45 / 73

Yes, this code is correct. It is identical to the code we used when explaining 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’ statement (implied a call to the get method), and the fact that we are assigning it a value in the myCar.ElapsedMileage = 10000000 statement (implies a call to the set method). If we add one more statement:

C#:

MessageBox.Show(myCar.ElapsedMileage.ToString());

  • what value do you think will be displayed? If you said 1 million

you'd be correct. That is because of the way that we wrote our set statement to filter out insane numbers like 10 million. One final point of clarification about the set; consider this line of code that was in the set statement above:

C#:

elapsedValue = value;

_

Where did the “value” identifier come from? In this case, C# uses this token (“value”) to represent the data that the property is being assigned to. It’s similar to an input parameter, but it’s built in and you can’t change the name of the identifier to anything else (like “mySetValue”, for example).

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



Document info
Document views145
Page views145
Page last viewedFri Dec 02 20:31:38 UTC 2016
Pages73
Paragraphs821
Words15988

Comments