TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C# Coding Standard
Search

Rule:  9@108Checked automatically with code checker

Synopsis:Use delegate inference instead of explicit delegate instantiation when possible
Language:C#
Severity Level:9
Category:Delegates and events


Description:

Using delegate inference for subscribing to and unsubscribing from event, code can be made much more elegant than the old previous way, which was like:

   someClass.SomeEvent += new EventHandler(OnHandleSomeEvent);
   private void OnHandleSomeEvent(object sender, EventArgs e)
   {...}

This can now be replaced by:

   someClass.SomeEvent += OnHandleSomeEvent;
   private void OnHandleSomeEvent(object sender, EventArgs e)
   {...}
}

Note: this only applies to code written in C# 2.0 and higher.