![Page 1: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/1.jpg)
Visual Studio 2010and
.NET Framework 4
Training Workshop
Visual Studio 2010and
.NET Framework 4
Training Workshop
![Page 2: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/2.jpg)
What’s New InC# 4.0 and Visual Basic
10
What’s New InC# 4.0 and Visual Basic
10NameTitleOrganizationEmail
![Page 3: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/3.jpg)
Essence versus Ceremony
Simple, Concise, Expressive
![Page 4: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/4.jpg)
Ceremony in C# 3.0Ceremony in C# 3.0
Removing “magic values” via temporaryvariables
GenerateChart(20, true);
var processCount = 20; var copyToWord = true; GenerateChart(processCount, copyToWord);
![Page 5: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/5.jpg)
Ceremony in C# 3.0Ceremony in C# 3.0
Removing “magic values” via temporaryvariables
GenerateChart(20, true);
GenerateChart(20 /* processCount */, true /* copyToWord */);
![Page 6: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/6.jpg)
Ceremony in C# 3.0Ceremony in C# 3.0
Optional parameters via method overloading
void GenerateChart(int processCount) { GenerateChart(processCount, false); }
void GenerateChart(int processCount, bool copyToWord) { // Do Something }
![Page 7: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/7.jpg)
Ceremony in C# 3.0Ceremony 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, ref Missing.Value);
![Page 8: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/8.jpg)
Essence vs. Ceremony in C# 4.0
Essence vs. Ceremony in C# 4.0
![Page 9: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/9.jpg)
Ceremony in VB 9Ceremony 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
![Page 10: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/10.jpg)
Ceremony in VB 9Ceremony 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
![Page 11: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/11.jpg)
Ceremony in VB 9Ceremony in VB 9
Line continuations must be specifiedby the developer
SomeLongMethodCall(firstParam, _ secondParam, _ thirdParam, _ fourthParam, _ fifthParam)
![Page 12: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/12.jpg)
Essence vs. Ceremony in VB 10Essence vs. Ceremony in VB 10
![Page 13: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/13.jpg)
Why a “Dynamic Language Runtime”?Why a “Dynamic Language Runtime”?
Common Language Runtime
Statically-Typed
C#VB
RubyPython
Dynamically-Typed
![Page 14: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/14.jpg)
Why a “Dynamic Language Runtime”?Why a “Dynamic Language Runtime”?
Common Language Runtime
Statically-Typed
C#VB
RubyPython
Dynamically-Typed
Dynamic Language Runtime
![Page 15: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/15.jpg)
Ceremony in C# 3.0Ceremony in C# 3.0
Dynamic Language interop ispainful
Calculator calc = GetCalculator(); int sum = calc.Add(10, 20);
![Page 16: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/16.jpg)
Ceremony in C# 3.0Ceremony in C# 3.0
Dynamic Language interop ispainful
object calc = GetCalculator(); Type calcType = calc.GetType(); object res = calcType.InvokeMember("Add", BindingFlags.InvokeMethod, null, new object[] { 10, 20 }); int sum = Convert.ToInt32(res);
![Page 17: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/17.jpg)
Ceremony in C# 3.0Ceremony in C# 3.0
Dynamic Language interop ispainful
ScriptObject calc = GetCalculator(); object res = calc.Invoke("Add", 10, 20); int sum = Convert.ToInt32(res);
![Page 18: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/18.jpg)
Essence in C# 4.0Essence in C# 4.0
Dynamic Language interopdoesn’t have to be painful!
dynamic calc = GetCalculator(); int sum = calc.Add(10, 20);
Statically typed to be
dynamic
Dynamic method
invocationDynamic
conversion
![Page 19: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/19.jpg)
The power of late-bindingThe power of late-binding
![Page 20: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/20.jpg)
New Features in C# 4.0 & VB 10
New Features in C# 4.0 & VB 10
Feature VB10 C#4
Auto-implemented Properties
Collection Initializers
Statement Lambdas
Implicit Line Continuation N/A
Named/Optional Parameters
Latebinding support (dynamic)
Omit ref on COM calls
New in Dev10Already exists in VB9/C#3
![Page 21: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/21.jpg)
New Features in C# 4.0 & VB 10
New Features in C# 4.0 & VB 10
Feature VB10 C#4
Auto-implemented Properties
Collection Initializers
Statement Lambdas
Implicit Line Continuation N/A
Named/Optional Parameters
Latebinding support (dynamic)
Omit ref on COM calls
Interop with Dynamic Languages
Co/contravariance
PIA deployment not needed
New in Dev10Already exists in VB9/C#3
![Page 22: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/22.jpg)
New Features in C# 4.0 & VB 10
New Features in C# 4.0 & VB 10
Feature VB10 C#4
Auto-implemented Properties
Collection Initializers
Statement Lambdas
Implicit Line Continuation N/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 Dev10Already exists in VB9/C#3
![Page 23: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/23.jpg)
Fixing The Type System…Fixing The Type System…
Covariance and Contravariance…
sounds complicated…
But it’s not!sort of…
![Page 24: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/24.jpg)
Fixing The Type System…Fixing The Type System…
How are generic types “broken” today?
var sheep = new List<Sheep>(); Speak(sheep);
void Speak(IEnumerable<Animal> animals) { // Do something with Animals }
class Animal { } class Sheep : Animal { }
Not Allowed:IEnumerable<Animal> != IEnumerable<Sheep>
![Page 25: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/25.jpg)
Break it down…Break it down…
Covariance – think “out”
Contravariance – think “in”
![Page 26: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/26.jpg)
Fixing The Type System…Fixing The Type System…Covariance and Contravariance
Sounds complicated!
http://tinyurl.com/genericvariance
![Page 27: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/27.jpg)
Essence versus Ceremony
![Page 28: Visual Studio 2010 and.NET Framework 4 Training Workshop](https://reader035.vdocuments.net/reader035/viewer/2022062300/56649d185503460f949ed9e8/html5/thumbnails/28.jpg)