?
Solved

Properties and fields

Posted on 2014-04-15
2
Medium Priority
?
147 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

765 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