checks for 3 objects

Hi;

I need to check for 3 objects, say foo of type string, baz of type object and bar as of type string.

if foo exists, i do fooDo
else i do bazDo and assign baz value to bar
and finally as a last resort i go for barDo but if bar is null i gave an output.

I try to do this in try catch, and nesting ifs. Any ideas for pseudocode?

Regards.
LVL 12
jazzIIIloveAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
try
{
  if (!String.IsNullOrEmpty(foo))
      fooDo();
   else if (baz != null)
{
      bazDo();
      bar = baz;
}
else if (bar != null)
    barDo();
else
   // output;
   
       
}

catch (exception ex)
{
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
I would only suggest a stylistic (subjective) change to ged325's code. I would not use the brace-less if and else blocks. Coming back to this code at later date, it would be easy to add in new logic with the assumption that it would be executed as its associated block. In other words, I would add braces to the if and else blocks above.

e.g.

if (!String.IsNullOrEmpty(foo))
{
    fooDo();
}

...

else
{
    // output;
}

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.