?
Solved

Using Get Set

Posted on 2013-06-05
5
Medium Priority
?
219 Views
Last Modified: 2013-06-05
Hi guys,

I have the following class:
public class DropdownColumnNumberMatch
        {
            public string RFQ_Number { get; set; }
        }

Open in new window


Then outside of that class:
private DropdownColumnNumberMatch Instance_DropdownColumnNumberMatch;

Open in new window


Then later in the project....

Instance_DropdownColumnNumberMatch = new DropdownColumnNumberMatch();

Instance_DropdownColumnNumberMatch.RFQ_Number = "Unset";

Open in new window


This is to set a default, I know im doing it wrong/inefficiently, now I tried the following but it errors, so how do I set a default in this case?

public class DropdownColumnNumberMatch
        {
            public string RFQ_Number { get { return RFQ_Number; } set { RFQ_Number = "Unset"; } }
        }

Thanks,
Dean

Open in new window

0
Comment
Question by:deanlee17
[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
  • 2
5 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 2000 total points
ID: 39221670
set default in constructor:
    public class DropdownColumnNumberMatch
    {
        public DropdownColumnNumberMatch()
        {
            RFQ_Number = "Unset";
        }

        public string RFQ_Number { get; set; }
    }

Open in new window

0
 

Author Comment

by:deanlee17
ID: 39221684
Thank you kind sir. So to add another it would simply be....

 public class DropdownColumnNumberMatch
    {
        public DropdownColumnNumberMatch()
        {
            RFQ_Number = "Unset";
            AnotherValue = "Unset";
        }

        public string RFQ_Number { get; set; }
        public string AnotherValue  { get; set; }
    } 

Open in new window

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39221687
yes exactly, constructor is one place to set default values to public properties.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39221821
FYI:  This would actually result in an endless loop:

public string RFQ_Number { get { return RFQ_Number; } ...

Open in new window

0
 

Author Comment

by:deanlee17
ID: 39221851
Thanks
0

Featured Post

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

762 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