X hits on this document

PDF document

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

152 views

0 shares

0 downloads

0 comments

43 / 73

C#:

private int

elapsedMileage;

_

Notice that I changed the underscore and capitalization of _elapsedMileage in keeping with our Best Practices (defined above). Private member variables should be camel cased and be prefixed with an underscore. And then create a public property called ElapsedMileage:

C#:

public int ElapsedMileage {

get {

return 5;

} set {

// Do nothing

}

}

Notice that there are two distinct parts of the property statement ... a get and a set. The get retrieves and returns a value to the code that calls it. The set assigns a value (more about this in a moment). Note that the first line of the property statement does nothing by itself; we have to decide which value to return when the get statement is called and what to do with the value that is passed into the parameter of the set statement. We could ignore these values, "hard code" them, or whatever we like. Typically, we'll do this:

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



Document info
Document views152
Page views152
Page last viewedSat Dec 03 14:34:07 UTC 2016
Pages73
Paragraphs821
Words15988

Comments