Select...Case VB.NET to C# Equivalent
Posted
by Alex Essilfie
on Stack Overflow
See other posts from Stack Overflow
or by Alex Essilfie
Published on 2010-03-16T09:42:37Z
Indexed on
2010/03/16
9:46 UTC
Read the original article
Hit count: 246
vb.net-to-c#
|conversion
I just started using C# and I've got a couple of issues.
I hook several controls to one event handler as in the following and I want to perform a slightly different action for each control:
Private Sub Button_Click(sender as Object, e as EventArgs) _
Handles button1.Click, Button2.Click
'do a general activity
Select CType(sender, Button).Name
Case button1.Name
'do something
Case button2.Name
'do something else
Case Else
'do the defalut action
End Select
End Sub
Is there any way of doing the above select statement in C# without having to use nested ifs?
© Stack Overflow or respective owner