230 likes | 367 Views
DEV318. Upgrading Your C# Programming Skills to Be a More Effective Developer. Mark Michaelis Lucian Wischik Chief Computer Nerd Senior Program Manager IntelliTechture Microsoft. About Us. Mark Michaelis Lucian Wischik IntelliTechture Microsoft
E N D
DEV318 Upgrading Your C# Programming Skills to Be a More Effective Developer Mark Michaelis Lucian Wischik Chief Computer Nerd Senior Program Manager IntelliTechture Microsoft
About Us Mark Michaelis Lucian Wischik IntelliTechture Microsoft Chief Computer Nerd, Senior Program Manager onAuthor & Trainer Languages Team
Agenda C# 1.0 C# 2.0 C# 3.0 C# 4.0
Auto-implemented PropertiesA Simplified Syntax • Reduce code clutter • Use everywhere for properties that are • Not Calculated • Don’t require interception (like validation) Call to Action • Use everywhere a simple property with backing field is used C# 2.0
Optional and Named Parameters • Reduce the need for overloading • Makes Office COM interoperability much easier Call to Action • Available in place of overloading C# 4.0
From object … to <T> • Replaces runtime errors with compile time errors • Reduces need for boxing especially with collections • Intellisense returns Call to Action • object is suspicious (indicates code smell) • Rely on implied type parameters unless overloaded with non-generic type that uses object • Favor generic collections (like List<T>) over arrays C# 2.0
Collection Initializers • Enable array like initialization with generic types • Type must support an Add<T>(T item) method Call to Action • Favor in place of arrays C# 3.0
Nullable<T> / int? • Allow for values types to store null • Implicitly cast value type to nullable type • Explicitly cast nullable type to value type • Supports coalesce operator (??) Call to Action • Use whenever a value type needs to store null C# 2.0
Generic Constraints • Avoid runtime cast exceptions • May be combined with as logical AND constraints • Support class (reference type) and struct (value type) Call to Action • Use to in place of explicit cast operations C# 2.0
yield return • Simplifies collection (IEnumerable<T>) implementation • Used infrequently but invaluable when used Call to Action • Consider yield return for custom IEnumerable<T>implementation or IEnumerable<T> return parameter. C# 2.0
Extension Methods • Extend types you don’t control • Used infrequently but invaluable when used Call to Action • Use gingerly • Restrict to interfaces that you don’t control or can’t be changed C# 3.0
Generic Delegates • Reduces the need to declare delegates Call to Action • Favor EventHandler<T>, Action<T, …>, Func<T, …> • Only declare delegates to clarify type parameters C# 2.0/3.0
Lambda Expressions • Replace explicit method declaration • Useful when delegate parameter varies frequently • Enables “passing” local variables without parameters or class members • Available in both expression and statement forms Call to Action • Embrace lambda expressions/statements • Favor lambdas over anonymous methods from C# 2.0 C# 3.0
LINQ • Transforms collection API • Available via standard query operators or query expressions • Enables object relational mapping • Fully strongly typed Call to Action • Embrace LINQ • Avoid uninttended deferred execution C# 3.0
Implicitly Typed Local Variables • Required for anonymous types • Equivalent to using the explicit types when available • Must be assigned at declaration time Call to Action • Only use when required or when the data type is obvious • Avoid when data type is complex (unless using anonymous types) C# 3.0
Contact Info. Mark Michaelis Lucian Wischik IntelliTechture Microsoft Chief Computer Nerd, Senior Program Manager onAuthor & Trainer Languages Team mark@IntelliTechture.com
DEV Track Resources • http://www.microsoft.com/visualstudio • http://www.microsoft.com/visualstudio/en-us/lightswitch • http://www.microsoft.com/expression/ • http://blogs.msdn.com/b/somasegar/ • http://blogs.msdn.com/b/bharry/ • http://www.microsoft.com/sqlserver/en/us/default.aspx • http://www.facebook.com/visualstudio
Resources • Connect. Share. Discuss. http://northamerica.msteched.com Learning • Sessions On-Demand & Community • Microsoft Certification & Training Resources www.microsoft.com/teched www.microsoft.com/learning • Resources for IT Professionals • Resources for Developers http://microsoft.com/technet http://microsoft.com/msdn
© 2011 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.