Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# Switch Syntax
Message
De
04/02/2011 10:54:38
 
 
À
04/02/2011 10:53:22
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01498737
Message ID:
01498752
Vues:
53
>>>Hi,
>>>
>>>How can I do something like this in C#?
>>>
>>>
                switch (myVar)
>>>                {
>>>                    case (1 || 2):
>>>                        // Do some stuff
>>>                        break;
>>>
>>>                    default:
>>>                        break;
>>>                }
>>>
>>>I get an error: Operator '||' cannot be applied to operands of type 'int' and 'int'
>>>
>>>Or does the switch statement only allow one possibility per case?
>>
>>You can do it like this
>>
>>
                switch (myVar)
>>                {
>>                    case 1:
>>                    case 2:
>>                        // Do some stuff
>>                        break;
>>
>>                    default:
>>                        break;
>>                }
>
>Ah, I see! Thanks.


see http://msdn.microsoft.com/en-us/library/06tc147t(VS.80).aspx
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform