/* LIFE RUNS ON CODE*/ Konstantinos Pantos Microsoft MVP ASP.NET Software Solutions Architect http://blog.pantos.name kostas@pantos.name
agenda C# 4 Language and Compiler features Visual C# Integrated Development Environment (VS 2010) features Parallel Programming in VS 2010
What’s New in C# 4.0
Dynamic Support Dynamic Lookup New dynamic type Resolution of method calls or field accesses is deferred until runtime Allows for calling or accessing identical methods or properties across unrelated objects Visual C# 2010 provides support for late binding to dynamic types by introducing a new type, dynamic. This addition enables many new scenarios, including simplified access to COM APIs such as the Office Automation APIs, to dynamic APIs such as IronPython libraries, and to the HTML Document Object Model (DOM). For more information, see Using Type dynamic (C# Programming Guide) and dynamic (C# Reference).
Dynamic Support Dynamic Lookup DLR – Dynamic Language Runtime is underlying mechanism This could be done before, using reflection or interfaces etc, but it would require much more work
Dynamic Demo
Dynamic support (Insight) C# is statically typed language How did it became dynamic? DLR (Dynamic Language Runtime) in play
Dynamic Programming DLR is additional libraries to fit the dynamic languages into the CLR Store program/code as data Caching mechanism for dynamic call Provide language specific support
Dynamic Programming Pros Cons No risk of brittle class hierarchy Need not implement all methods of interface More flexible , highly productive Cons Developer needs thorough understanding of codebase Misuse might lead to poor maintainability
Named and Optional Parameters Historically multiple overloads were required to achieve this type of thing in c# Named parameters were never possible Now this can be done using the optional argument syntax in a single constructor
Named – Optional Demo
Variance Variance is one of those things most of us don’t often have to think about comes naturally There are some cases which you may assume should work that don’t however.
Variance The following example does not work even though string obviously inherits from object If it did, the following would have to work, which goes against type safety IList<string> strings = new List<string>(); IList<object> objects = strings; Objects[0] = 5; String s = strings[0];
Covariance and Contravariance There may however be times where you would want to have this type of thing happening and for it to happen safely C# 4.0 allows for covariance and contravariance through the new out and in keywords Works only for interfaces and delegates Works only for reference types Actual bits don’t change
Covariance Contravariance Demo
Office programmability Removes dependency on Office PIAs Language enhancements C# Optional Parameters, Named Arguments, Dynamic types
Demo: Excel Add In
Visual C# Integrated Development Environment
Call Hierarchy Call Hierarchy enables navigation through code by displaying the following: All calls to and from a selected method, property, or constructor All implementations of an interface member All overrides of a virtual or abstract member Enables better understanding of how code flows and evaluation of the effects of changes to code.
Navigate To Search for a symbol or file in source code Search for keywords that are contained in a symbol by using Camel casing and underscore characters to divide the symbol into keywords
Highlighting References When you click a symbol in source code, all instances of that symbol are highlighted in the document. You can move to the next or previous highlighted symbol, by CTRL+SHIFT+DOWN ARROW or CTRL+SHIFT+UP ARROW
Generate From Usage Enables usage of classes and members before defining them. Generate a stub for a class, constructor, method, property, field, or enum before defining it. Minimizes interruption of workflow
IntelliSense Suggestion Mode Two alternatives for IntelliSense statement completion Completion mode Suggestion mode Used when classes and members are used before they are defined
Live Semantic Errors Wavy underlines which signal errors and warnings as you type has been extended to include constructs that are outside of method bodies. Return types, Parameter types, Default values in method declarations
Visual C# IDE Demo
Parallel programming
Parallel Computing Features. Parallel API Parallel Profiling Parallel debugger Concurrency visualizer in VS2010
Parallel Programming Demo
Resources What’s new in Visual C# 2010 http://msdn.microsoft.com/en-us/library/bb383815.aspx Visual Studio 2010 http://msdn.microsoft.com/el-gr/vstudio/ff625297(en-us).aspx Parallel Computing http://msdn.microsoft.com/en-us/concurrency/default.aspx Daniel Moth http://www.danielmoth.com/Blog
Thank you