enum and switch

  • Thread starter Thread starter salvatore.difazio
  • Start date Start date
S

salvatore.difazio

Hi guys,
I've an Enum like this

public Enum Pippo
{
giovanni,
giuseppe,
lino
};

and I would like to use this enum in a switch case like this:

switch(myvariable.PippoType)
{
case Pippo.giovanni:
break:
case Pippo.giuseppe:
break;
case Pippo.lino:
break;
}

Does anybody tell me how can I do that?
 
Does anybody tell me how can I do that?
´
You just did. Your code should work fine as long as you change "Enum"
to "enum" and "break:" to "break;".



Mattias
 
if myvariable is Pipo (enum) type you should write just:

switch(myvariable)
{
case Pippo.giovanni:
break:
case Pippo.giuseppe:
break;
case Pippo.lino:
break;
}
 
Appart from doing it by hand as you did in your post, there is a Switch
Assistant feature in my add-in (below) to generate the case statements
automatically.

--
Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 
Cannot implicitly convert type
'myNameSpace.Pippo' to 'string'

with a

switch (myvariable)
{
case myNameSpace.Pippo.giovanni:
break;
etc.....
}
 
Cannot implicitly convert type
'myNameSpace.Pippo' to 'string'

with a

switch (myvariable)
{
case myNameSpace.Pippo.giovanni:
break;
etc.....
}

Then your switch-expression (myvariable) is of type string.
It should be of type Pippo
 
Back
Top