Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# switch ?
Message
General information
Forum:
ASP.NET
Category:
Other
Title:
Miscellaneous
Thread ID:
00779532
Message ID:
00779790
Views:
24
Dmitry,

You can use elseif in C#; it just doesn't look the same as in VB.
if (iTime == iBegin)
    Response.Write("iTime = iBegin");
else if (iTime > iBegin && iTime < iEnd)
    Response.Write("iTime > iBegin and < iEnd");
else if (iTime == iEnd)
    Response.Write("iTime = iEnd");
else
    // something else
>Bonnie,
>This is what I understood how switch works, or I would prefer to say "does not work" <g>. I am surprised that such a highly touted language as C# does not have a more flexible switch/do case. In VB you can at least use ELSEIF. But in C# I will have to do a lot of IF/ELSE/IF/ELSE, and so on.
>
>Thank you.
>
>P.S. Please ignore the following. This is just a test:
>
>test
>
>
>>Dmitry,
>>
>>The switch/case statement in C# is definitely way more limiting than in VFP. You can't do what you're trying to do with a switch/case, you'd need to use if statements. The only part of the switch/case that you've used that is actually valid is just this:
>>
>>switch (iTime)
>>{
>>  case iBegin :
>>       Response.Write("iTime = iBegin");
>>       break;
>>  case iEnd:
>>      Response.Write("iTime = iEnd");
>>      break;
>>}
>>
>>
>>You can only test that the variable is equal to what you specify in the case, that's it.
>>
>>~~Bonnie
>>
>>
>>>I am probably misunderstanding something about use of switch statement. My understanding was that switch should function just like do case in VFP. Yet I find switch quite limitted, unless I misunderstand something.
>>>
>>>Here is a simple example of switch that does not work:
>>>
>>>int iTime = 5;
>>>int iBegin = 5;
>>>int iEnd = 7;
>>>
>>>switch (iTime)
>>> {
>>> case iTime == iBegin:
>>> Response.Write("iTime = iBegin");
>>> break;
>>> case iTime > iBegin && iTime < iEnd:
>>> Response.Write("iTime > iBegin and < iEnd");
>>> break;
>>> case iTime == iEnd:
>>> Response.Write("iTime = iEnd");
>>> break;
>>> }
>>>
>>>Yet, in VFP you can use DO CASE to compare the three values in a manner shown in the example above.
>>>
>>>What am I missing?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform