PC Review


Reply
Thread Tools Rate Thread

c# equivalent to select case true

 
 
TS
Guest
Posts: n/a
 
      28th Sep 2005
i used to do this in vb and haven't been able to in c# - any workaround?


 
Reply With Quote
 
 
 
 
Brendan Green
Guest
Posts: n/a
 
      28th Sep 2005
Show us a code sample in VB what you want to do.

As a guess, you're not talking about the switch keyword, are you?

"TS" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>i used to do this in vb and haven't been able to in c# - any workaround?
>



 
Reply With Quote
 
Robbe Morris [C# MVP]
Guest
Posts: n/a
 
      28th Sep 2005
switch(myvariable)
{
case "blah":
return;
default:
return false;
}

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net





"TS" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>i used to do this in vb and haven't been able to in c# - any workaround?
>



 
Reply With Quote
 
Frank Rizzo
Guest
Posts: n/a
 
      28th Sep 2005
TS wrote:

>i used to do this in vb and haven't been able to in c# - any workaround?
>
>

switch (true)
{
case 1:
break;
default:
break;

}
 
Reply With Quote
 
=?Utf-8?B?RGF2aWQgQW50b24=?=
Guest
Posts: n/a
 
      28th Sep 2005
In VB, you are able to do this since the case statements can include a wide
range of expressions. In C#, the case expressions must be constant, so the
usefulness of this technique is greatly reduced.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter
Clear VB: Cleans up outdated VB.NET code


"TS" wrote:

> i used to do this in vb and haven't been able to in c# - any workaround?
>
>
>

 
Reply With Quote
 
TS
Guest
Posts: n/a
 
      28th Sep 2005
thanks, yes i am looking for a
switch(true)
{
case var1 = 5 : ...
case var9 = 21: ...

i guess you can't do it as i thought

"David Anton" <(E-Mail Removed)> wrote in message
news:76EEC0AC-8206-43F9-81F7-(E-Mail Removed)...
> In VB, you are able to do this since the case statements can include a
> wide
> range of expressions. In C#, the case expressions must be constant, so
> the
> usefulness of this technique is greatly reduced.
> --
> David Anton
> www.tangiblesoftwaresolutions.com
> Instant C#: VB.NET to C# Converter
> Instant VB: C# to VB.NET Converter
> Instant J#: VB.NET to J# Converter
> Clear VB: Cleans up outdated VB.NET code
>
>
> "TS" wrote:
>
>> i used to do this in vb and haven't been able to in c# - any workaround?
>>
>>
>>



 
Reply With Quote
 
Bruce Wood
Guest
Posts: n/a
 
      28th Sep 2005
No, you can't do this in C#. Other languages have this kind of switch
construct:

switch (value)
{
case expression:
case expression:
...
default:
}

C# (as well as C, C++, and Java) has this kind of switch construct:

switch (expression)
{
case constant:
case constant:
case constant:
...
default:
}

So, no. You have to use if... else if... else if... else.

 
Reply With Quote
 
Christof Nordiek
Guest
Posts: n/a
 
      29th Sep 2005
"TS" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
> thanks, yes i am looking for a
> switch(true)
> {
> case var1 = 5 : ...
> case var9 = 21: ...
>
> i guess you can't do it as i thought
>

<snip>
you can:
the c# equivalent is:

if (var1 == 5)
{
.....
}
else if (var9 == 21)
{
......
}
........


 
Reply With Quote
 
TS
Guest
Posts: n/a
 
      29th Sep 2005
thank you all, thats what i thought!


"Christof Nordiek" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> "TS" <(E-Mail Removed)> schrieb im Newsbeitrag
> news:(E-Mail Removed)...
>> thanks, yes i am looking for a
>> switch(true)
>> {
>> case var1 = 5 : ...
>> case var9 = 21: ...
>>
>> i guess you can't do it as i thought
>>

> <snip>
> you can:
> the c# equivalent is:
>
> if (var1 == 5)
> {
> .....
> }
> else if (var9 == 21)
> {
> ......
> }
> .......
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
translate VB select case to switch case problem Rich P Microsoft C# .NET 13 8th Aug 2009 06:07 PM
Forms/Reports Select Case Statement equivalent epoh97 via AccessMonster.com Microsoft Access Forms 5 21st Jul 2006 03:58 PM
Case statement equivalent ricky Microsoft Access Queries 9 25th Mar 2006 08:37 PM
CASE statement equivalent Beema Microsoft Excel Worksheet Functions 1 15th Dec 2004 09:32 AM
C++ equivalent of a case =?Utf-8?B?aW5mYWVs?= Microsoft Access Form Coding 2 26th May 2004 12:55 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:35 AM.