Solved

Using Get Set

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expression Evaluater 3 37
SSRS Deployment problem 5 64
ASP.NET MVC -Update model when click on <li> element 29 29
reading excel file in .net 2 14
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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