SlideShare a Scribd company logo
1 of 25
What’s new in C# 4? Kevin Pilch-Bisson [email_address] http://twitter.com/Pilchie
The Evolution of C# C# 1.0 C# 2.0 C# 3.0 Managed Code Generics Language Integrated Query
Trends
The Evolution of C# C# 1.0 C# 2.0 C# 3.0 Managed Code Generics Language Integrated Query C# 4.0 Dynamic Programming
C# 4.0 Language Innovations
.NET Dynamic Programming Python Binder Ruby Binder COM Binder JavaScript Binder Object Binder Dynamic Language Runtime Expression Trees Dynamic Dispatch Call Site Caching IronPython IronRuby C# VB.NET Others…
Dynamically Typed Objects Calculator  calc = GetCalculator(); int  sum = calc.Add(10, 20); object  calc = GetCalculator(); Type  calcType = calc.GetType(); object  res = calcType.InvokeMember( "Add" , BindingFlags.InvokeMethod,  null , new   object [] { 10, 20 }); int  sum = Convert.ToInt32(res); ScriptObject  calc = GetCalculator(); object  res = calc.Invoke( "Add" , 10, 20); int  sum =  Convert .ToInt32(res); dynamic  calc = GetCalculator(); int  sum = calc.Add(10, 20); Statically  typed to be dynamic Dynamic method invocation Dynamic conversion
Dynamically Typed Objects dynamic  calc = GetCalculator(); dynamic  sum = calc.Add( 10 ,  20 ); Another word for System.Object… ,[object Object],[object Object],[object Object],[object Object],[object Object],… but with dynamic semantics
Dynamically Typed Objects public static class  Math { public   static   decimal  Abs( decimal  value); public   static   double  Abs( double  value); public   static   float  Abs( float  value); public   static   int  Abs( int  value); public   static   long  Abs( long  value); public   static   sbyte  Abs( sbyte  value); public   static   short  Abs( short  value); ... } double  x = 1.75; double  y =  Math .Abs(x);   dynamic  x = 1.75; dynamic  y =  Math .Abs(x);   dynamic  x = 2; dynamic  y =  Math .Abs(x);   Method chosen at compile-time: double Abs(double x) Method chosen at run-time:  double Abs(double x) Method chosen at run-time:  int Abs(int x)
Dynamically Typed Objects dynamic  d = GetDynamicObject(...); d.Foo(10,  "Hello" );  // Method invocation int  size = d.Width;  // Property access d.x = 25;  // Field access d[ "one" ] = d[ "two" ];  // Indexer access int  i = d + 3;  // Operator application string  s = d(5, 10);  // Delegate invocation
Dynamically Typed Objects
Optional and Named Parameters public   StreamReader  OpenTextFile( string  path, Encoding  encoding, bool  detectEncoding, int  bufferSize); public   StreamReader  OpenTextFile( string  path, Encoding  encoding, bool  detectEncoding); public   StreamReader  OpenTextFile( string  path, Encoding  encoding); public   StreamReader  OpenTextFile( string  path); Primary method Secondary overloads Call primary with default values
Optional and Named Parameters public   StreamReader  OpenTextFile( string  path, Encoding  encoding, bool  detectEncoding, int  bufferSize); public   StreamReader  OpenTextFile( string  path, Encoding  encoding =  null , bool  detectEncoding =  true , int  bufferSize = 1024); Optional parameters OpenTextFile( "foo.txt" ,  Encoding .UTF8); OpenTextFile( "foo.txt" ,  Encoding .UTF8, bufferSize: 4096); Named argument OpenTextFile( bufferSize: 4096, path:  "foo.txt" , detectEncoding:  false ); Named arguments must be last Non-optional must be specified Evaluated in order written Named arguments  can be in any order
Improved COM Interoperability object  fileName =  "Test.docx" ; object  missing  = System.Reflection. Missing .Value; doc.SaveAs( ref  fileName, ref  missing,  ref  missing,  ref  missing, ref  missing,  ref  missing,  ref  missing, ref  missing,  ref  missing,  ref  missing, ref  missing,  ref  missing,  ref  missing, ref  missing,  ref  missing,  ref  missing); doc.SaveAs( "Test.docx" );
Improved COM Interoperability ,[object Object],[object Object],[object Object],[object Object],[object Object]
Improved COM Interoperability
Co- and Contra-variance void  Process( object [] objects) { … } string [] strings = GetStringArray(); Process(strings); void  Process( object [] objects) { objects[0] =  &quot;Hello&quot; ;  // Ok objects[1] =  new   Button ();  // Exception! } List < string > strings = GetStringList(); Process(strings); void  Process( IEnumerable < object > objects) { … } .NET arrays are co-variant … but  not safely co-variant Until now, C# generics have been  invariant void  Process( IEnumerable < object > objects) { // IEnumerable<T> is read-only and // therefore safely co-variant } C# 4.0 supports  safe  co- and contra-variance
Safe Co- and Contra-variance public   interface   IEnumerable <T> { IEnumerator <T> GetEnumerator(); } public   interface   IEnumerator <T> { T Current {  get ; } bool  MoveNext(); } public   interface   IEnumerable < out  T> { IEnumerator <T> GetEnumerator(); } public   interface   IEnumerator < out  T> { T Current {  get ; } bool  MoveNext(); } out  = Co-variant Output positions only IEnumerable < string > strings = GetStrings(); IEnumerable < object > objects = strings; Can be treated as less derived public   interface   IComparer <T> { int  Compare(T x, T y); } public   interface   IComparer < in  T> { int  Compare(T x, T y); } IComparer < object > objComp = GetComparer(); IComparer < string > strComp = objComp; in  = Contra-variant Input positions only Can be treated as more derived
Variance in C# 4.0 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Variance in .NET Framework 4.0 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Interfaces ,[object Object],[object Object],[object Object],[object Object],[object Object],Delegates
The Evolution of C# C# 1.0 C# 2.0 C# 3.0 Managed Code Generics Language Integrated Query C# 4.0 Dynamic Programming
Compiler as a Service Source code Source code Source File Source code Source code .NET Assembly Meta-programming Read-Eval-Print Loop Language Object Model DSL Embedding Compiler Compiler Class Field public Foo private string X
Compiler as a Service
Questions?
© 2010 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. Required Slide

More Related Content

What's hot

Reflection in Go
Reflection in GoReflection in Go
Reflection in Gostrikr .
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeDmitri Nesteruk
 
Design Patterns in Modern C++
Design Patterns in Modern C++Design Patterns in Modern C++
Design Patterns in Modern C++Dmitri Nesteruk
 
Introduction to Go programming language
Introduction to Go programming languageIntroduction to Go programming language
Introduction to Go programming languageSlawomir Dorzak
 
Golang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewGolang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewMarkus Schneider
 
Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operationsarchikabhatia
 
C++11 concurrency
C++11 concurrencyC++11 concurrency
C++11 concurrencyxu liwei
 
Fantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOFFantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOFDror Bereznitsky
 
Kotlin as a Better Java
Kotlin as a Better JavaKotlin as a Better Java
Kotlin as a Better JavaGarth Gilmour
 
Go Programming Language (Golang)
Go Programming Language (Golang)Go Programming Language (Golang)
Go Programming Language (Golang)Ishin Vin
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by ExampleOlve Maudal
 
Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17OdessaFrontend
 

What's hot (19)

C++11
C++11C++11
C++11
 
Reflection in Go
Reflection in GoReflection in Go
Reflection in Go
 
Unmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/InvokeUnmanaged Parallelization via P/Invoke
Unmanaged Parallelization via P/Invoke
 
Design Patterns in Modern C++
Design Patterns in Modern C++Design Patterns in Modern C++
Design Patterns in Modern C++
 
C++ Presentation
C++ PresentationC++ Presentation
C++ Presentation
 
Introduction to Go programming language
Introduction to Go programming languageIntroduction to Go programming language
Introduction to Go programming language
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Golang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewGolang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / Overview
 
Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operations
 
C++11 concurrency
C++11 concurrencyC++11 concurrency
C++11 concurrency
 
Fantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOFFantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOF
 
Kotlin as a Better Java
Kotlin as a Better JavaKotlin as a Better Java
Kotlin as a Better Java
 
Python The basics
Python   The basicsPython   The basics
Python The basics
 
Go Programming Language (Golang)
Go Programming Language (Golang)Go Programming Language (Golang)
Go Programming Language (Golang)
 
C++11
C++11C++11
C++11
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by Example
 
Python programming
Python  programmingPython  programming
Python programming
 
Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17
 
C++ How to program
C++ How to programC++ How to program
C++ How to program
 

Viewers also liked

devLink - VB IDE Tips and Tricks for Visual Studio 2010
devLink - VB IDE Tips and Tricks for Visual Studio 2010devLink - VB IDE Tips and Tricks for Visual Studio 2010
devLink - VB IDE Tips and Tricks for Visual Studio 2010Kevin Pilch
 
Calculator and how to make it using VB 6.0
Calculator and how to make it using VB 6.0Calculator and how to make it using VB 6.0
Calculator and how to make it using VB 6.0surajkumarpadhy
 
Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)pbarasia
 
Visual Basic Codes And Screen Designs
Visual Basic Codes And Screen DesignsVisual Basic Codes And Screen Designs
Visual Basic Codes And Screen Designsprcastano
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsLinkedIn
 

Viewers also liked (6)

devLink - VB IDE Tips and Tricks for Visual Studio 2010
devLink - VB IDE Tips and Tricks for Visual Studio 2010devLink - VB IDE Tips and Tricks for Visual Studio 2010
devLink - VB IDE Tips and Tricks for Visual Studio 2010
 
Calculator and how to make it using VB 6.0
Calculator and how to make it using VB 6.0Calculator and how to make it using VB 6.0
Calculator and how to make it using VB 6.0
 
Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)Presentation on visual basic 6 (vb6)
Presentation on visual basic 6 (vb6)
 
Visual Basic Codes And Screen Designs
Visual Basic Codes And Screen DesignsVisual Basic Codes And Screen Designs
Visual Basic Codes And Screen Designs
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 
Study: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving CarsStudy: The Future of VR, AR and Self-Driving Cars
Study: The Future of VR, AR and Self-Driving Cars
 

Similar to devLink - What's New in C# 4?

Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Juan Pablo
 
PDC Video on C# 4.0 Futures
PDC Video on C# 4.0 FuturesPDC Video on C# 4.0 Futures
PDC Video on C# 4.0 Futuresnithinmohantk
 
Whats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoWhats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoPaulo Morgado
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharpg_hemanth17
 
Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1Sachin Singh
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharpRaga Vahini
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharpSatish Verma
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharpsinghadarsh
 
Introduction to CSharp
Introduction to CSharpIntroduction to CSharp
Introduction to CSharpMody Farouk
 
Is your C# optimized
Is your C# optimizedIs your C# optimized
Is your C# optimizedWoody Pewitt
 
Introduction to c sharp 4.0 and dynamic
Introduction to c sharp 4.0 and dynamicIntroduction to c sharp 4.0 and dynamic
Introduction to c sharp 4.0 and dynamicGieno Miao
 
C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8Christian Nagel
 
IntroToCSharpcode.ppt
IntroToCSharpcode.pptIntroToCSharpcode.ppt
IntroToCSharpcode.pptpsundarau
 
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05CHOOSE
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard LibrarySantosh Rajan
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAdam Getchell
 

Similar to devLink - What's New in C# 4? (20)

Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
 
PDC Video on C# 4.0 Futures
PDC Video on C# 4.0 FuturesPDC Video on C# 4.0 Futures
PDC Video on C# 4.0 Futures
 
Whats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoWhats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPonto
 
Linq intro
Linq introLinq intro
Linq intro
 
PostThis
PostThisPostThis
PostThis
 
Introduction To Csharp
Introduction To CsharpIntroduction To Csharp
Introduction To Csharp
 
Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Introduction to CSharp
Introduction to CSharpIntroduction to CSharp
Introduction to CSharp
 
Is your C# optimized
Is your C# optimizedIs your C# optimized
Is your C# optimized
 
Introduction to c sharp 4.0 and dynamic
Introduction to c sharp 4.0 and dynamicIntroduction to c sharp 4.0 and dynamic
Introduction to c sharp 4.0 and dynamic
 
C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8C# 7.x What's new and what's coming with C# 8
C# 7.x What's new and what's coming with C# 8
 
IntroToCSharpcode.ppt
IntroToCSharpcode.pptIntroToCSharpcode.ppt
IntroToCSharpcode.ppt
 
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
02basics
02basics02basics
02basics
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
 
C
CC
C
 

Recently uploaded

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 

Recently uploaded (20)

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 

devLink - What's New in C# 4?

  • 1. What’s new in C# 4? Kevin Pilch-Bisson [email_address] http://twitter.com/Pilchie
  • 2. The Evolution of C# C# 1.0 C# 2.0 C# 3.0 Managed Code Generics Language Integrated Query
  • 4. The Evolution of C# C# 1.0 C# 2.0 C# 3.0 Managed Code Generics Language Integrated Query C# 4.0 Dynamic Programming
  • 5. C# 4.0 Language Innovations
  • 6. .NET Dynamic Programming Python Binder Ruby Binder COM Binder JavaScript Binder Object Binder Dynamic Language Runtime Expression Trees Dynamic Dispatch Call Site Caching IronPython IronRuby C# VB.NET Others…
  • 7. Dynamically Typed Objects Calculator calc = GetCalculator(); int sum = calc.Add(10, 20); object calc = GetCalculator(); Type calcType = calc.GetType(); object res = calcType.InvokeMember( &quot;Add&quot; , BindingFlags.InvokeMethod, null , new object [] { 10, 20 }); int sum = Convert.ToInt32(res); ScriptObject calc = GetCalculator(); object res = calc.Invoke( &quot;Add&quot; , 10, 20); int sum = Convert .ToInt32(res); dynamic calc = GetCalculator(); int sum = calc.Add(10, 20); Statically typed to be dynamic Dynamic method invocation Dynamic conversion
  • 8.
  • 9. Dynamically Typed Objects public static class Math { public static decimal Abs( decimal value); public static double Abs( double value); public static float Abs( float value); public static int Abs( int value); public static long Abs( long value); public static sbyte Abs( sbyte value); public static short Abs( short value); ... } double x = 1.75; double y = Math .Abs(x); dynamic x = 1.75; dynamic y = Math .Abs(x); dynamic x = 2; dynamic y = Math .Abs(x); Method chosen at compile-time: double Abs(double x) Method chosen at run-time: double Abs(double x) Method chosen at run-time: int Abs(int x)
  • 10. Dynamically Typed Objects dynamic d = GetDynamicObject(...); d.Foo(10, &quot;Hello&quot; ); // Method invocation int size = d.Width; // Property access d.x = 25; // Field access d[ &quot;one&quot; ] = d[ &quot;two&quot; ]; // Indexer access int i = d + 3; // Operator application string s = d(5, 10); // Delegate invocation
  • 12. Optional and Named Parameters public StreamReader OpenTextFile( string path, Encoding encoding, bool detectEncoding, int bufferSize); public StreamReader OpenTextFile( string path, Encoding encoding, bool detectEncoding); public StreamReader OpenTextFile( string path, Encoding encoding); public StreamReader OpenTextFile( string path); Primary method Secondary overloads Call primary with default values
  • 13. Optional and Named Parameters public StreamReader OpenTextFile( string path, Encoding encoding, bool detectEncoding, int bufferSize); public StreamReader OpenTextFile( string path, Encoding encoding = null , bool detectEncoding = true , int bufferSize = 1024); Optional parameters OpenTextFile( &quot;foo.txt&quot; , Encoding .UTF8); OpenTextFile( &quot;foo.txt&quot; , Encoding .UTF8, bufferSize: 4096); Named argument OpenTextFile( bufferSize: 4096, path: &quot;foo.txt&quot; , detectEncoding: false ); Named arguments must be last Non-optional must be specified Evaluated in order written Named arguments can be in any order
  • 14. Improved COM Interoperability object fileName = &quot;Test.docx&quot; ; object missing = System.Reflection. Missing .Value; doc.SaveAs( ref fileName, ref missing,  ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); doc.SaveAs( &quot;Test.docx&quot; );
  • 15.
  • 17. Co- and Contra-variance void Process( object [] objects) { … } string [] strings = GetStringArray(); Process(strings); void Process( object [] objects) { objects[0] = &quot;Hello&quot; ; // Ok objects[1] = new Button (); // Exception! } List < string > strings = GetStringList(); Process(strings); void Process( IEnumerable < object > objects) { … } .NET arrays are co-variant … but not safely co-variant Until now, C# generics have been invariant void Process( IEnumerable < object > objects) { // IEnumerable<T> is read-only and // therefore safely co-variant } C# 4.0 supports safe co- and contra-variance
  • 18. Safe Co- and Contra-variance public interface IEnumerable <T> { IEnumerator <T> GetEnumerator(); } public interface IEnumerator <T> { T Current { get ; } bool MoveNext(); } public interface IEnumerable < out T> { IEnumerator <T> GetEnumerator(); } public interface IEnumerator < out T> { T Current { get ; } bool MoveNext(); } out = Co-variant Output positions only IEnumerable < string > strings = GetStrings(); IEnumerable < object > objects = strings; Can be treated as less derived public interface IComparer <T> { int Compare(T x, T y); } public interface IComparer < in T> { int Compare(T x, T y); } IComparer < object > objComp = GetComparer(); IComparer < string > strComp = objComp; in = Contra-variant Input positions only Can be treated as more derived
  • 19.
  • 20.
  • 21. The Evolution of C# C# 1.0 C# 2.0 C# 3.0 Managed Code Generics Language Integrated Query C# 4.0 Dynamic Programming
  • 22. Compiler as a Service Source code Source code Source File Source code Source code .NET Assembly Meta-programming Read-Eval-Print Loop Language Object Model DSL Embedding Compiler Compiler Class Field public Foo private string X
  • 23. Compiler as a Service
  • 25. © 2010 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. Required Slide

Editor's Notes

  1. Move towards more declarative styles of programming Domain specific, Functional Resurgence of dynamic programming languages Meta-programming Need for better concurrent programming models Distributed applications Many-core Trends cause fusing of ideas from previously distinct disciplines Functional in mainstream languages Static typing in dynamic languages Implicit typing in static languages Domain specific in every app HTML, SQL, XAML, XSLT The classic taxonomies are breaking down Going forward, mainstream GPLs will be multi-paradigm!
  2. 08/10/10 17:56 © 2007 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.