Visual Studio 2010 and NET Framework 4 Training

  • Slides: 28
Download presentation
Visual Studio 2010 and. NET Framework 4 Training Workshop

Visual Studio 2010 and. NET Framework 4 Training Workshop

What’s New In C# 4. 0 and Visual Basic 10 Name Title Organization Email

What’s New In C# 4. 0 and Visual Basic 10 Name Title Organization Email

Essence versus Ceremony Simple, Concise, Expressive

Essence versus Ceremony Simple, Concise, Expressive

Ceremony in C# 3. 0 Removing “magic values” via temporary variables Generate. Chart(20, true);

Ceremony in C# 3. 0 Removing “magic values” via temporary variables Generate. Chart(20, true); var process. Count = 20; var copy. To. Word = true; Generate. Chart(process. Count, copy. To. Word);

Ceremony in C# 3. 0 Removing “magic values” via temporary variables Generate. Chart(20, true);

Ceremony in C# 3. 0 Removing “magic values” via temporary variables Generate. Chart(20, true); Generate. Chart(20 /* process. Count */, true /* copy. To. Word */);

Ceremony in C# 3. 0 Optional parameters via method overloading void Generate. Chart(int process.

Ceremony in C# 3. 0 Optional parameters via method overloading void Generate. Chart(int process. Count) { Generate. Chart(process. Count, false); } void Generate. Chart(int process. Count, bool copy. To. Word) { // Do Something }

Ceremony in C# 3. 0 Ugly COM Interop and the ever-present “ref Missing. Value”

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);

Essence vs. Ceremony in C# 4. 0

Essence vs. Ceremony in C# 4. 0

Ceremony in VB 9 Backing fields for properties are explicit Private m_name As String

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 (By. Val value As String) m_name = value End Property

Ceremony in VB 9 Popularity of lambda-based libraries cause problems for VB developers Sub

Ceremony in VB 9 Popularity of lambda-based libraries cause problems for VB developers Sub My. Method() Lambda. Call(Function(i) Temp. Method(i) End Sub Function) Introduction of Function Temp. Method(Dim param as Integer) As Nothing temporary Console. Write. Line(param) functions Return Nothing End Function “Hacks” since statement lambdas not supported

Ceremony in VB 9 Line continuations must be specified by the developer Some. Long.

Ceremony in VB 9 Line continuations must be specified by the developer Some. Long. Method. Call(first. Param, _ second. Param, _ third. Param, _ fourth. Param, _ fifth. Param)

Essence vs. Ceremony in VB 10

Essence vs. Ceremony in VB 10

Why a “Dynamic Language Runtime”? Dynamically-Typed Python Statically-Typed C# VB Common Language Runtime Ruby

Why a “Dynamic Language Runtime”? Dynamically-Typed Python Statically-Typed C# VB Common Language Runtime Ruby

Why a “Dynamic Language Runtime”? Dynamically-Typed Python Ruby Statically-Typed C# VB Dynamic Language Runtime

Why a “Dynamic Language Runtime”? Dynamically-Typed Python Ruby Statically-Typed C# VB Dynamic Language Runtime Common Language Runtime

Ceremony in C# 3. 0 Dynamic Language interop is painful Calculator calc = Get.

Ceremony in C# 3. 0 Dynamic Language interop is painful Calculator calc = Get. Calculator(); int sum = calc. Add(10, 20);

Ceremony in C# 3. 0 Dynamic Language interop is painful object calc = Get.

Ceremony in C# 3. 0 Dynamic Language interop is painful object calc = Get. Calculator(); Type calc. Type = calc. Get. Type(); object res = calc. Type. Invoke. Member("Add", Binding. Flags. Invoke. Method, null, new object[] { 10, 20 }); int sum = Convert. To. Int 32(res);

Ceremony in C# 3. 0 Dynamic Language interop is painful Script. Object calc =

Ceremony in C# 3. 0 Dynamic Language interop is painful Script. Object calc = Get. Calculator(); object res = calc. Invoke("Add", 10, 20); int sum = Convert. To. Int 32(res);

Essence in C# 4. 0 Dynamic Language interop doesn’t have to be painful! Statically

Essence in C# 4. 0 Dynamic Language interop doesn’t have to be painful! Statically typed to be dynamic calc = Get. Calculator(); int sum = calc. Add(10, 20); Dynamic conversion Dynamic method invocation

The power of late-binding

The power of late-binding

New Features in C# 4. 0 & VB 10 Feature VB 10 C#4 Auto-implemented

New Features in C# 4. 0 & VB 10 Feature VB 10 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 Dev 10 Already exists in VB 9/C#3

New Features in C# 4. 0 & VB 10 Feature VB 10 C#4 Auto-implemented

New Features in C# 4. 0 & VB 10 Feature VB 10 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 Dev 10 Already exists in VB 9/C#3

New Features in C# 4. 0 & VB 10 Feature VB 10 C#4 Auto-implemented

New Features in C# 4. 0 & VB 10 Feature VB 10 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 Dev 10 Already exists in VB 9/C#3

Fixing The Type System… Covariance and Contravariance… sounds complicated… But it’s not! sort of…

Fixing The Type System… Covariance and Contravariance… sounds complicated… But it’s not! sort of…

Fixing The Type System… How are generic types “broken” today? class Animal { }

Fixing The Type System… How are generic types “broken” today? class Animal { } class Sheep : Animal { } void Speak(IEnumerable<Animal> animals) { Not Allowed: // Do something with Animals IEnumerable<Animal> } != IEnumerable<Sheep> var sheep = new List<Sheep>(); Speak(sheep);

Break it down… Covariance – think “out” Contravariance – think “in”

Break it down… Covariance – think “out” Contravariance – think “in”

Fixing The Type System… Covariance and Contravariance Sounds complicated! http: //tinyurl. com/genericvariance

Fixing The Type System… Covariance and Contravariance Sounds complicated! http: //tinyurl. com/genericvariance

Essence versus Ceremony

Essence versus Ceremony