avoid case statement

  • Thread starter Thread starter raulavi
  • Start date Start date
R

raulavi

c# vs2008
HI:
I have to replace a string with somevalue, I use the case
any Ideas how to better implement this (avoid regex if possible).
(was thinking of a dictionary?)
thanks
case "a"
myvar = "1a"
break
case "w"
myvar = "bb"
break
case "L"
myvar = "po"
break
 
raulavi said:
c# vs2008
HI:
I have to replace a string with somevalue, I use the case
any Ideas how to better implement this (avoid regex if possible).
(was thinking of a dictionary?)
thanks
case "a"
myvar = "1a"
break
case "w"
myvar = "bb"
break
case "L"
myvar = "po"
break

You'be answered your own question. Use a dictionary.
 
c# vs2008
HI:
I have to replace a string with somevalue, I use the case
any Ideas how to better implement this (avoid regex if possible).
(was thinking of a dictionary?)
thanks
case "a"
    myvar = "1a"
   break
case "w"
    myvar = "bb"
   break
case "L"
    myvar = "po"
    break

A dictionary could be used, but I think that you need to explain
better your escenario, like if the possible values change both of the
to be replaced string and the replacing string.
In your code you are not "replacing" you are simply assigning
 
thanks to all
the scenario is very basic...
long lists everywhere
there are many pair (case) every where in this c# code (framework 2.0) I
will love to use linq, but will wait for 3.0
I would like to organize them nicelly as:
listIn = "a,w,L..."
listOut = "1a,bb,po..."
myvar = for listIn use listOut;
(nice future feature eh?)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top