private void ButtonClick(object sender, EventArgs e)
{
    Button btn = (Button)sender;

    switch(btn.Name)
    {
        case "btn1":
            Console.WriteLine("btn1");
            break;

        case "btn2":
            Console.WriteLine("btn2");
            break;

        default:
            Console.WriteLine("default");
            break;
    }
 }

Regards,
Gary Harpin

Software Developer,
Research & Development Department.
________________________________

The other day upon the stair, I saw a man who wasn't there. He wasn't
there again today, I think he's from the CIA.


| -----Original Message-----
| From: Mike Andrews [mailto:[EMAIL PROTECTED]
| Sent: Tuesday, June 20, 2006 2:54 PM
| 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 DevelopMentor(r)  http://www.develop.com
|
| View archives and manage your subscription(s) at
| http://discuss.develop.com

Signam Ltd.,Harris Road, Warwick, England. CV34 5FY.
Tel: +44 (0)1926 417300 Fax: +44 (0)1926 417333
www.signam.co.uk www.sportsmark.co.uk

  _____

Company registered in England, number 1972268

This message (and any associated files) is intended only for the use of
the individual or entity to which it is addressed and may contain
information that is confidential, subject to copyright or constitutes a
trade secret. If you are not the intended recipient you are hereby
notified that any dissemination, copying or distribution of this
message, or files associated with this message, is strictly prohibited.
If you have received this message in error, please notify us immediately
by replying to the message and deleting it from your computer. Messages
sent to and from us may be monitored.

Internet communications cannot be guaranteed to be secure or error-free
as information could be intercepted, corrupted, lost, destroyed, arrive
late or incomplete, or contain viruses. Therefore, we do not accept
responsibility for any errors or omissions that are present in this
message, or any attachment, that have arisen as a result of e-mail
transmission. If verification is required, please request a hard-copy
version. Any views or opinions presented are solely those of the author
and do not necessarily represent those of the company.



===================================
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