'this.ID = id;' in class construction
Hi,
I have a question on the 'ArticleDetails' Class on page 219.
Previously I have created class properties by doing the following:
- pass a parameter into the class constructor as follows:
public ArticleDetails(int ID)
- declare a private field within the class:
private int _id = 0;
- declare a public property withint the class:
public int ID
{
get { return _id; }
set { _id = value; }
}
However, on page 219, the parameter passed into the class is:
id, as in public ArticleDetails(int id)
rather than:
ID, as in public ArticleDetails(int ID)
And there is the additional statement:
this.ID = id;
What is the purpose of doing it this way? Is it just a difference of syntax which achieves exactly the same thing, or is there something else going on here?
Is 'this.ID' available due to the public property declaration later on in the code, i.e. 'public int ID'?
Basically, the way I have known to do this involves two variables,
_id and ID
The example on page 219 involves three variables:
_id, ID and id
Why is this?
Any thoughts on this would be much appreciated.
Thanks! :)
Holf
|