dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[DotGNU].net futures


From: Neil Cawse
Subject: [DotGNU].net futures
Date: Fri, 22 Aug 2003 19:39:34 -0400

 Feed: Don Box's Spoutlet
 Title: The Perils of Pre-Disclosure
 
I've noticed several people referencing this summary of new C# features over on GDN lately in response to the recent flurry of discussion on delegates.
 
Readers should be aware that the syntax for anonymous methods has changed somewhat since that whitepaper was posted. Specifically, one no longer uses the name of the delegate type when declaring the anonymous method.
 
For example, this code excerpted from the aforementioned whitepaper:
 
public MyForm()

{
      listBox = new ListBox(...);
      textBox = new TextBox(...);
      button = new Button(...);
      button.Click += new EventHandler(sender, e)
      {
      listBox.Items.Add(textBox.Text);
      };
   }
}
 
would now be written like this:
 
public MyForm()
{
      listBox = new ListBox(...);
      textBox = new TextBox(...);
      button = new Button(...);
      button.Click += delegate(object sender, EventArgs e)
      {
      listBox.Items.Add(textBox.Text);
      };
   }
}
 
It's also worth noting that this example illustrates two new features. The obvious one is the anonymous method feature. The more subtle feature is the fact that Whidbey C# relaxes the requirement to explicitly instantiate a delegate type. For example, consider the first example (not using anonymous methods):
 
public MyForm()

{
      listBox = new ListBox(...);
      textBox = new TextBox(...);
      button = new Button(...);
      button.Click += new EventHandler(AddClick);
   }
}
 
In whidbey C#, you are allowed to (but not required to) omit the "new T" and just do the assignment:
 
public MyForm()
{
      listBox = new ListBox(...);
      textBox = new TextBox(...);
      button = new Button(...);
      button.Click += AddClick;
   }
}
 
Shades of C function pointers!
 
Of course, readers should be aware that the moment after I click the submit button all of this might change yet again (unlikely but not impossible).
 
As always, consult the actual bits (which can be had at PDC in October).

reply via email to

[Prev in Thread] Current Thread [Next in Thread]