SlideShare uma empresa Scribd logo
1 de 22
C# 4.0 and .NET 4.0 Buu Nguyen, MVP (ASP.NET) www.buunguyen.net/blog buunguyen@kms-technology.com Microsoft Confidential 1
Agenda Optional and Named Parameters Covariance and Contravariance Dynamic Binding Threading with Task API Task Parallel Library (TPL) PLINQ
Optional and Named Parameters
?Quiz What are 2 issues of this API?
Covariance and Contravariance
?Quiz What is wrong with this code?
Covariance Defined Let’s say S is subtype of B and GT is a generic type GT<S> behaves like subtype of GT<B> on assignment compatibility, i.e. GT<S> s = … GT<B> b = s; GT<S> s = (GT<S>)b; Safe only when GT doesn’t expose members “receiving” T as input (aka input-safe) Microsoft Confidential 7
?Quiz What is wrong with this code?
Contravariance Defined Let’s say S is subtype of B and GT is a generic type GT<B> behaves like subtype of GT<S> on assignment compatibility, i.e. GT<B> b = … GT<S> s = b; GT<B> b = (GT<B>)s; Safe only when GT doesn’t expose members “returning” T as output (aka output-safe) Microsoft Confidential 9
Dynamic Binding
?Quiz Write a method that prints out the Name property of an anonymous object returned by another method
Dynamic binding means… use runtime type for all bindings
?Quiz A method summing Length properties of all parameters, regardless of actual type
?Quiz How to builds C# objects that behave like JavaScript objects, i.e. members can be added at any time?
?Quiz Write a class whose objects can invoke static methods of any particular type Bonus #1: include non-public static methods Bonus #2: ignore case
?Quiz Write a class whose objects can be used as result-caching proxy for the method invocation of any other object
Task Parallel Library (TPL) & PLINQ
?Quiz Write a method calculating Fibonacci number using a thread in thread-pool and returning result to caller
Task Parallelism Features Wait on tasks Support parent-child relationship Exception handling Cancelling tasks Continuation Execute one task after another Microsoft Confidential 19
?Quiz Write 3 methods: Calculate some known Fibonacci numbers Calculate Fibonacci numbers for a range Calculate Fibonacci numbers for a list of specified indexes Each calculation must take place in a thread in thread-pool
Parallel Class Assign delegates to a handful of Task instances, not one-to-one mapping
?Quiz Write a method which calculate some specified Fibonacci numbers and return the sum of them to the caller

Mais conteúdo relacionado

Mais procurados

C#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New FeaturesC#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New Features
techfreak
 

Mais procurados (18)

C#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New FeaturesC#3.0 & Vb 9.0 New Features
C#3.0 & Vb 9.0 New Features
 
Testing Challenges within Agile Teams
Testing Challenges within Agile TeamsTesting Challenges within Agile Teams
Testing Challenges within Agile Teams
 
ANTLR4 in depth
ANTLR4 in depthANTLR4 in depth
ANTLR4 in depth
 
Elixir Brasil 2019 - Quality: A Panacéia para seu código Elixir
Elixir Brasil 2019 - Quality:  A Panacéia para seu código ElixirElixir Brasil 2019 - Quality:  A Panacéia para seu código Elixir
Elixir Brasil 2019 - Quality: A Panacéia para seu código Elixir
 
PHP Reactive Programming at Medan Tech Day 2018
PHP Reactive Programming at Medan Tech Day 2018PHP Reactive Programming at Medan Tech Day 2018
PHP Reactive Programming at Medan Tech Day 2018
 
Data Generation with PROSPECT: a Probability Specification Tool
Data Generation with PROSPECT: a Probability Specification ToolData Generation with PROSPECT: a Probability Specification Tool
Data Generation with PROSPECT: a Probability Specification Tool
 
From Java to Kotlin
From Java to KotlinFrom Java to Kotlin
From Java to Kotlin
 
Algorithm pseudocode flowchart program notes
Algorithm pseudocode flowchart program notesAlgorithm pseudocode flowchart program notes
Algorithm pseudocode flowchart program notes
 
End-to-End Machine learning pipelines for Python driven organizations - Nick ...
End-to-End Machine learning pipelines for Python driven organizations - Nick ...End-to-End Machine learning pipelines for Python driven organizations - Nick ...
End-to-End Machine learning pipelines for Python driven organizations - Nick ...
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
 
Python Programming language
Python Programming languagePython Programming language
Python Programming language
 
CS152 Programming Paradigm
CS152 Programming Paradigm CS152 Programming Paradigm
CS152 Programming Paradigm
 
Review june2014 june2015
Review june2014 june2015Review june2014 june2015
Review june2014 june2015
 
Code Reviews in Python - PyZh
Code Reviews in Python - PyZhCode Reviews in Python - PyZh
Code Reviews in Python - PyZh
 
Internal domain-specific languages
Internal domain-specific languagesInternal domain-specific languages
Internal domain-specific languages
 
Kotlin
KotlinKotlin
Kotlin
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
 
Programming paradigms
Programming paradigmsProgramming paradigms
Programming paradigms
 

Destaque

Xamarin 3 hieu 19-06
Xamarin 3   hieu 19-06Xamarin 3   hieu 19-06
Xamarin 3 hieu 19-06
Nguyen Hieu
 
Mobile Cross-Platform App Development in C# with Xamarin
Mobile Cross-Platform App Development in C# with XamarinMobile Cross-Platform App Development in C# with Xamarin
Mobile Cross-Platform App Development in C# with Xamarin
Nick Landry
 

Destaque (20)

Csharp ebook
Csharp ebookCsharp ebook
Csharp ebook
 
C# 4.0 dynamic
C# 4.0 dynamicC# 4.0 dynamic
C# 4.0 dynamic
 
Dynamic C#
Dynamic C# Dynamic C#
Dynamic C#
 
Switch to Results in Hotels
Switch to Results in HotelsSwitch to Results in Hotels
Switch to Results in Hotels
 
Xamarin Cross-Platform with Xamarin.Form, MvvmCross
Xamarin Cross-Platform with Xamarin.Form, MvvmCrossXamarin Cross-Platform with Xamarin.Form, MvvmCross
Xamarin Cross-Platform with Xamarin.Form, MvvmCross
 
Xamarin 3 hieu 19-06
Xamarin 3   hieu 19-06Xamarin 3   hieu 19-06
Xamarin 3 hieu 19-06
 
C# Is The Future
C# Is The FutureC# Is The Future
C# Is The Future
 
Enterprise Mobile Success with Oracle and Xamarin
Enterprise Mobile Success with Oracle and XamarinEnterprise Mobile Success with Oracle and Xamarin
Enterprise Mobile Success with Oracle and Xamarin
 
C# 6.0 - What?! C# is being updated?
C# 6.0 - What?! C# is being updated?C# 6.0 - What?! C# is being updated?
C# 6.0 - What?! C# is being updated?
 
Mobile Enterprise Success with Xamarin and IBM
Mobile Enterprise Success with Xamarin and IBMMobile Enterprise Success with Xamarin and IBM
Mobile Enterprise Success with Xamarin and IBM
 
C# 3.0 and 4.0
C# 3.0 and 4.0C# 3.0 and 4.0
C# 3.0 and 4.0
 
Mobile Cross-Platform App Development in C# with Xamarin
Mobile Cross-Platform App Development in C# with XamarinMobile Cross-Platform App Development in C# with Xamarin
Mobile Cross-Platform App Development in C# with Xamarin
 
Xamarin Mobile Leaders Summit: Business at the Point of Inspiration: Producti...
Xamarin Mobile Leaders Summit: Business at the Point of Inspiration: Producti...Xamarin Mobile Leaders Summit: Business at the Point of Inspiration: Producti...
Xamarin Mobile Leaders Summit: Business at the Point of Inspiration: Producti...
 
Xamarin Mobile Leaders Summit: The Mobile Mind Shift: Opportunities, Challeng...
Xamarin Mobile Leaders Summit: The Mobile Mind Shift: Opportunities, Challeng...Xamarin Mobile Leaders Summit: The Mobile Mind Shift: Opportunities, Challeng...
Xamarin Mobile Leaders Summit: The Mobile Mind Shift: Opportunities, Challeng...
 
Xamarin Mobile Leaders Summit | Solving the Unique Challenges in Mobile DevOps
Xamarin Mobile Leaders Summit | Solving the Unique Challenges in Mobile DevOpsXamarin Mobile Leaders Summit | Solving the Unique Challenges in Mobile DevOps
Xamarin Mobile Leaders Summit | Solving the Unique Challenges in Mobile DevOps
 
Building Your First Xamarin.Forms App
Building Your First Xamarin.Forms AppBuilding Your First Xamarin.Forms App
Building Your First Xamarin.Forms App
 
Xamarin Việt Nam - Lập trình cross platform mobile app - https://uxvietnam.com
Xamarin Việt Nam - Lập trình cross platform mobile app - https://uxvietnam.comXamarin Việt Nam - Lập trình cross platform mobile app - https://uxvietnam.com
Xamarin Việt Nam - Lập trình cross platform mobile app - https://uxvietnam.com
 
Building Your First Android App with Xamarin
Building Your First Android App with XamarinBuilding Your First Android App with Xamarin
Building Your First Android App with Xamarin
 
Intro to Xamarin for Visual Studio: Native iOS, Android, and Windows Apps in C#
Intro to Xamarin for Visual Studio: Native iOS, Android, and Windows Apps in C#Intro to Xamarin for Visual Studio: Native iOS, Android, and Windows Apps in C#
Intro to Xamarin for Visual Studio: Native iOS, Android, and Windows Apps in C#
 
Native i os, android, and windows development in c# with xamarin 4
Native i os, android, and windows development in c# with xamarin 4Native i os, android, and windows development in c# with xamarin 4
Native i os, android, and windows development in c# with xamarin 4
 

Semelhante a C# 4.0 and .NET 4.0

Top 40 C Programming Interview Questions
Top 40 C Programming Interview QuestionsTop 40 C Programming Interview Questions
Top 40 C Programming Interview Questions
Simplilearn
 
Qtp interview questions
Qtp interview questionsQtp interview questions
Qtp interview questions
Ramu Palanki
 
Qtp interview questions
Qtp interview questionsQtp interview questions
Qtp interview questions
Ramu Palanki
 
Agile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tddAgile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tdd
Srinivasa GV
 
.NET 4 Demystified - Sandeep Joshi
.NET 4 Demystified - Sandeep Joshi.NET 4 Demystified - Sandeep Joshi
.NET 4 Demystified - Sandeep Joshi
Spiffy
 

Semelhante a C# 4.0 and .NET 4.0 (20)

C# advanced topics and future - C#5
C# advanced topics and future - C#5C# advanced topics and future - C#5
C# advanced topics and future - C#5
 
C Types - Extending Python
C Types - Extending PythonC Types - Extending Python
C Types - Extending Python
 
Tdd in practice
Tdd in practiceTdd in practice
Tdd in practice
 
Python typing module
Python typing modulePython typing module
Python typing module
 
Top 40 C Programming Interview Questions
Top 40 C Programming Interview QuestionsTop 40 C Programming Interview Questions
Top 40 C Programming Interview Questions
 
The Onward Journey: Porting Twisted to Python 3
The Onward Journey: Porting Twisted to Python 3The Onward Journey: Porting Twisted to Python 3
The Onward Journey: Porting Twisted to Python 3
 
How to do code review and use analysis tool in software development
How to do code review and use analysis tool in software developmentHow to do code review and use analysis tool in software development
How to do code review and use analysis tool in software development
 
Qtp interview questions
Qtp interview questionsQtp interview questions
Qtp interview questions
 
Qtp interview questions
Qtp interview questionsQtp interview questions
Qtp interview questions
 
UNIT IV (1).ppt
UNIT IV (1).pptUNIT IV (1).ppt
UNIT IV (1).ppt
 
Can't Dance The Lambda
Can't Dance The LambdaCan't Dance The Lambda
Can't Dance The Lambda
 
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
 
Python master class 2
Python master class 2Python master class 2
Python master class 2
 
Agile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tddAgile_goa_2013_clean_code_tdd
Agile_goa_2013_clean_code_tdd
 
.NET 4 Demystified - Sandeep Joshi
.NET 4 Demystified - Sandeep Joshi.NET 4 Demystified - Sandeep Joshi
.NET 4 Demystified - Sandeep Joshi
 
C+++
C+++C+++
C+++
 
Python Fundamentals Class 11
Python Fundamentals Class 11Python Fundamentals Class 11
Python Fundamentals Class 11
 
Moving to Python 3
Moving to Python 3Moving to Python 3
Moving to Python 3
 
Behavioral Reflection
Behavioral ReflectionBehavioral Reflection
Behavioral Reflection
 
SOLID principles
SOLID principlesSOLID principles
SOLID principles
 

Mais de Buu Nguyen (10)

On Becoming a Technical Lead
On Becoming a Technical LeadOn Becoming a Technical Lead
On Becoming a Technical Lead
 
Stories about KMS Technology
Stories about KMS TechnologyStories about KMS Technology
Stories about KMS Technology
 
ASP.NET MVC 3
ASP.NET MVC 3ASP.NET MVC 3
ASP.NET MVC 3
 
HTML5 in IE9
HTML5 in IE9HTML5 in IE9
HTML5 in IE9
 
Dynamic Binding in C# 4.0
Dynamic Binding in C# 4.0Dynamic Binding in C# 4.0
Dynamic Binding in C# 4.0
 
ASP.NET MVC 2.0
ASP.NET MVC 2.0ASP.NET MVC 2.0
ASP.NET MVC 2.0
 
Building Scalable .NET Web Applications
Building Scalable .NET Web ApplicationsBuilding Scalable .NET Web Applications
Building Scalable .NET Web Applications
 
New Features of ASP.NET 4.0
New Features of ASP.NET 4.0New Features of ASP.NET 4.0
New Features of ASP.NET 4.0
 
Combres
CombresCombres
Combres
 
Fasterflect
FasterflectFasterflect
Fasterflect
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

C# 4.0 and .NET 4.0

  • 1. C# 4.0 and .NET 4.0 Buu Nguyen, MVP (ASP.NET) www.buunguyen.net/blog buunguyen@kms-technology.com Microsoft Confidential 1
  • 2. Agenda Optional and Named Parameters Covariance and Contravariance Dynamic Binding Threading with Task API Task Parallel Library (TPL) PLINQ
  • 3. Optional and Named Parameters
  • 4. ?Quiz What are 2 issues of this API?
  • 6. ?Quiz What is wrong with this code?
  • 7. Covariance Defined Let’s say S is subtype of B and GT is a generic type GT<S> behaves like subtype of GT<B> on assignment compatibility, i.e. GT<S> s = … GT<B> b = s; GT<S> s = (GT<S>)b; Safe only when GT doesn’t expose members “receiving” T as input (aka input-safe) Microsoft Confidential 7
  • 8. ?Quiz What is wrong with this code?
  • 9. Contravariance Defined Let’s say S is subtype of B and GT is a generic type GT<B> behaves like subtype of GT<S> on assignment compatibility, i.e. GT<B> b = … GT<S> s = b; GT<B> b = (GT<B>)s; Safe only when GT doesn’t expose members “returning” T as output (aka output-safe) Microsoft Confidential 9
  • 11. ?Quiz Write a method that prints out the Name property of an anonymous object returned by another method
  • 12. Dynamic binding means… use runtime type for all bindings
  • 13. ?Quiz A method summing Length properties of all parameters, regardless of actual type
  • 14. ?Quiz How to builds C# objects that behave like JavaScript objects, i.e. members can be added at any time?
  • 15. ?Quiz Write a class whose objects can invoke static methods of any particular type Bonus #1: include non-public static methods Bonus #2: ignore case
  • 16. ?Quiz Write a class whose objects can be used as result-caching proxy for the method invocation of any other object
  • 17. Task Parallel Library (TPL) & PLINQ
  • 18. ?Quiz Write a method calculating Fibonacci number using a thread in thread-pool and returning result to caller
  • 19. Task Parallelism Features Wait on tasks Support parent-child relationship Exception handling Cancelling tasks Continuation Execute one task after another Microsoft Confidential 19
  • 20. ?Quiz Write 3 methods: Calculate some known Fibonacci numbers Calculate Fibonacci numbers for a range Calculate Fibonacci numbers for a list of specified indexes Each calculation must take place in a thread in thread-pool
  • 21. Parallel Class Assign delegates to a handful of Task instances, not one-to-one mapping
  • 22. ?Quiz Write a method which calculate some specified Fibonacci numbers and return the sum of them to the caller