Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
2
Answers
Basics clarification
S
12y
1.2k
1
Reply
Hi,
Given the following code:-
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
public string GetName()
{
return name;
}
public void SetName(string value)
{
name = value;
}
The first part is an example of an Automatic Get\Set property. The Get is returning the field value and the Set is setting the field value.
The second part is showing how the properties can be turned into methods to achieve the same thing.
My question is with that Constructors and Methods always seem to assign to Properties directly rather than the underlining fields as seen in the method examples GetName and SetName above? is the code just purely an example of how to achieve the same thing ie a like for like comparison?
Thanks
Steven
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
Repeater control with image in asp.net
Want some code help plz help me out