Solved

Using Get Set

Posted on 2013-06-05
5
215 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
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

813 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

8 Experts available now in Live!

Get 1:1 Help Now