if (sender == btn)
{
  //...
}
else if (sender == btn2)
{
  //...
}
else if (sender == btn3)
{
  //...
}



Thanks,

Shawn Wildermuth
http://adoguy.com
C# MVP, MCSD.NET, Author and Speaker




-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Mike Andrews
Sent: Tuesday, June 20, 2006 9:54 AM
To: [email protected]
Subject: [ADVANCED-DOTNET] VB's Select Case Equivalent in C#

Guys,

Does anyone know if something like this is possible in C#:

private void ButtonClick(object sender, EventArgs e) {

switch(true){

case (sender == btn1):
  ...
  break;

case (sender == btn2):
  ...
  break;

case (sender == btn3):
  ...
  break;

}


I've looked at sample code and read up on the switch statement and it
appears to be unavailable.
Why is that?  If C# is modern language, why does it not have some very
simple abilities that VB has had?
It seems that if you want to have one procedure handle the click events for
several buttons, that doing it this way is harder to read:

...
if (sender == btn1){
...
}else if (sender == btn2){
...
}else if (sender == btn3){
...
}
...

Thanks,
Mike

===================================
This list is hosted by DevelopMentorR  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to