Link to home
Start Free TrialLog in
Avatar of deanlee17
deanlee17

asked on

Using Get Set

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

ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deanlee17
deanlee17

ASKER

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

yes exactly, constructor is one place to set default values to public properties.
FYI:  This would actually result in an endless loop:

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

Open in new window

Thanks