Download presentation
Presentation is loading. Please wait.
Published byDella Lamb Modified over 9 years ago
1
Visual Studio 2010 and.NET Framework 4 Training Workshop
2
Presentation Outline (hidden slide): Technical Level: 300 Intended Audience: Developers & Architects Objectives (what do you want the audience to take away): Understand the new features and improvements to C# 4.0 Understand the new features and improvements to VB 10 Understand the ongoing relationship between C# and VB as they both evolve Presentation Outline: Where we’re at today LINQ/Declarative Language Trends C# (Evolution -> C# 4.0) Co-Evolution VB (Evolution -> VB 10) DLR
3
What’s New In C# 4.0 and Visual Basic 10 Name Title Organization Email
4
Essence versus Ceremony Simple, Concise, Expressive
5
Ceremony in C# 3.0 Removing “magic values” via temporary variables GenerateChart(20, true); var processCount = 20; var copyToWord = true; GenerateChart(processCount, copyToWord);
6
Ceremony in C# 3.0 Removing “magic values” via temporary variables GenerateChart(20, true); GenerateChart(20 /* processCount */, true /* copyToWord */);
7
Ceremony in C# 3.0 Optional parameters via method overloading void GenerateChart(int processCount) { GenerateChart(processCount, false); } void GenerateChart(int processCount, bool copyToWord) { // Do Something }
8
Ceremony in C# 3.0 Ugly COM Interop and the ever-present “ref Missing.Value” var word = new Word.Application(); word.Documents.Add(ref Missing.Value, ref Missing.Value, ref Missing.Value);
9
Essence vs. Ceremony in C# 4.0
10
Ceremony in VB 9 Backing fields for properties are explicit Private m_name As String Public Property Name() As String Get Name = m_name End Get Set (ByVal value As String) m_name = value End End Property
11
Ceremony in VB 9 Popularity of lambda-based libraries cause problems for VB developers Sub MyMethod() LambdaCall(Function(i) TempMethod(i) End Function) End Sub Function TempMethod(Dim param as Integer) As Nothing Console.WriteLine(param) Return Nothing End Function Introduction of temporary functions “Hacks” since statement lambdas not supported
12
Ceremony in VB 9 Line continuations must be specified by the developer SomeLongMethodCall(firstParam, _ secondParam, _ thirdParam, _ fourthParam, _ fifthParam)
13
Essence vs. Ceremony in VB 10
14
Why a “Dynamic Language Runtime”? Common Language Runtime Statically-Typed C# VB Ruby Python Dynamically-Typed
15
Why a “Dynamic Language Runtime”? Common Language Runtime Statically-Typed C# VB Ruby Python Dynamically-Typed Dynamic Language Runtime
16
Ceremony in C# 3.0 Dynamic Language interop is painful Calculator calc = GetCalculator(); int sum = calc.Add(10, 20);
17
Ceremony in C# 3.0 Dynamic Language interop is painful object calc = GetCalculator(); Type calcType = calc.GetType(); object res = calcType.InvokeMember("Add", BindingFlags.InvokeMethod, null, new object[] { 10, 20 }); int sum = Convert.ToInt32(res);
18
Ceremony in C# 3.0 Dynamic Language interop is painful ScriptObject calc = GetCalculator(); object res = calc.Invoke("Add", 10, 20); int sum = Convert.ToInt32(res);
19
Essence in C# 4.0 Dynamic Language interop doesn’t have to be painful! dynamic calc = GetCalculator(); int sum = calc.Add(10, 20); Statically typed to be dynamic Dynamic method invocation Dynamic conversion
20
The power of late-binding
21
New Features in C# 4.0 & VB 10 FeatureVB10C#4 Auto-implemented Properties Collection Initializers Statement Lambdas Implicit Line ContinuationN/A Named/Optional Parameters Latebinding support (dynamic) Omit ref on COM calls New in Dev10 Already exists in VB9/C#3
22
New Features in C# 4.0 & VB 10 FeatureVB10C#4 Auto-implemented Properties Collection Initializers Statement Lambdas Implicit Line ContinuationN/A Named/Optional Parameters Latebinding support (dynamic) Omit ref on COM calls Interop with Dynamic Languages Co/contravariance PIA deployment not needed New in Dev10 Already exists in VB9/C#3
23
New Features in C# 4.0 & VB 10 FeatureVB10C#4 Auto-implemented Properties Collection Initializers Statement Lambdas Implicit Line ContinuationN/A Named/Optional Parameters Latebinding support (dynamic) Omit ref on COM calls Interop with Dynamic Languages Co/contravariance PIA deployment not needed Iterators XML Literals New in Dev10 Already exists in VB9/C#3
24
Fixing The Type System… Covariance and Contravariance… sounds complicated… But it’s not! sort of…
25
Fixing The Type System… How are generic types “broken” today? var sheep = new List (); Speak(sheep); void Speak(IEnumerable animals) { // Do something with Animals } class Animal { } class Sheep : Animal { } Not Allowed: IEnumerable != IEnumerable Not Allowed: IEnumerable != IEnumerable
26
Break it down… Covariance – think “out” Contravariance – think “in”
27
Generic Variance Fixing the Type System
28
Fixing The Type System… Covariance and Contravariance Sounds complicated! http://tinyurl.com/genericvariance
29
Essence versus Ceremony
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.