Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Properties and fields

Posted on 2014-04-15
2
Medium Priority
?
148 Views
Last Modified: 2014-04-16
I know this is a basic question but I was watching PluralSight and was speaking with a coworker.

I've attached a screenshot of the lesson.  It doesn't need the
private int _age
public int Age
  {...}

Don't think it does because we just use {get; set;}  That's what I'm trying to explain to my coworker.
properties.png
0
Comment
Question by:Camillia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 1000 total points
ID: 40002572
You are correct.

The "backing field" _age is needed only if you want to reference it in some way, like the traditional:

private int _age
public int Age
{
     get { return _age;}
    set {
              _age = value;
// and maybe some more processing involving _age here....

}
}

Open in new window

0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 1000 total points
ID: 40002766
What you are referring to are known as "Automatic Properties" which declare and manage the hidden member value for you. It is basically a shorthand to save you having to write boiler plate code for properties that do nothing more than read/write directly to a value.

If you need to build more logic into your property then you need to use the long hand version.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question