Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Properties.Settings.Default, multiple values

Posted on 2010-11-11
7
Medium Priority
?
466 Views
Last Modified: 2012-05-10
I'm working on an application an we need conditional statements for multiple locations.
There could be two or more locations.

Is there another way of coding for a certain location?
So far, I would just use a conditional statement.
if (Properties.Settings.Default.Location == "abc")
                {
                   //do stuff
                }

Open in new window

0
Comment
Question by:JRockFL
  • 3
  • 2
  • 2
7 Comments
 
LVL 17

Accepted Solution

by:
Daniel Reynolds earned 2000 total points
ID: 34115568
well most obvious is using switch(){} but that may not save you much.

create the do stuff method()

switch (Properties.Setting.Default.Location)
{
     case "abc":
              dostuff("abc");
               break;
    case "bcd":
              dostuff("bcd")
              break;
}
0
 
LVL 8

Author Comment

by:JRockFL
ID: 34115609
Yeah I thought about that too, What about creating an enumerator?
Then when I instantiate the class,  I can set a property with the current location.

if (Location == Locations.Texas)
{
    //do stuff
}
0
 
LVL 17

Expert Comment

by:Daniel Reynolds
ID: 34115797
an enumerator will still require you to check which it is somehow using if or switch.

The creation of a class with methods / branches that will process depending on the value of its location property would be a clean way to implement this, but you still need to check the value in the class, just not in the calling method.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 6

Expert Comment

by:ajb2222
ID: 34116204
You could create a class that has specific methods and properties

then create a class for each location based on the first class you created and override any mothods or properties that are diferent for that location

Then when some processing just call the correct method.

Look into Object Oriented Programming.

0
 
LVL 8

Author Comment

by:JRockFL
ID: 34116299
ajb2222,

can you provide a code sample?
0
 
LVL 6

Expert Comment

by:ajb2222
ID: 34122123
what I am talking about is  inheritance and  polymorphism which are two major concepts in object oriented programming.  The link is an example that explains the concept and how to apply it.

http://www.codeproject.com/KB/cs/csharpintro01.aspx

0
 
LVL 8

Author Closing Comment

by:JRockFL
ID: 34248524
Thank you!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

963 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