Solved

Properties.Settings.Default, multiple values

Posted on 2010-11-11
7
454 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:
xDJR1875 earned 500 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:xDJR1875
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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.
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 tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 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

16 Experts available now in Live!

Get 1:1 Help Now