TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
357
120.8k
Basics clarification
Mar 30 2012 6:05 AM
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
Reply
Answers (
2
)
Repeater control with image in asp.net
Initialize Combo box with a blank item - LINQ C#