Anonymous methods
Use anonymous methods cautiously. Generally, apply the following rules: Ø Use anonymous method if you need up to five code lines; Ø Use anonymous method if you need capture one or two external variables. 5.7 C# 3.0 features Lambda expressions Ø Prefer methods over lambda expressions when the same code is used repeatedly. Ø Prefer lambda expressions where anonymous delegates would have been appropriate in C# 2.0. Extension methods Ø Try to avoid extension methods usage. Ø Put extension methods in their own static class. Ø Consider grouping extension methods that extend a particular class into a single static class, and name that class <ClassName>Extensions. Ø Keep extension method classes in their own namespace to mitigate potential name collisions (if you run into a name collision you're forced back to using a static method call). Anonymous types Do not use anonymous types (except for very short-lived data in LINQ). Implicitly types local variables Ø Prefer explicitly-typed local variables. Ø Do not use var with intrinsic types. Ø Use var with LINQ statements where the result is not an intrinsic type.
|