Solved

Using Get Set

Posted on 2013-06-05
5
213 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
  • 2
  • 2
5 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
yes exactly, constructor is one place to set default values to public properties.
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now