Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
C# 4.0 and .NET 4.0<br />Buu Nguyen, MVP (ASP.NET)<br />www.buunguyen.net/blog<br />buunguyen@kms-technology.com<br />Micr...
Agenda<br />Optional and Named Parameters<br />Covariance and Contravariance<br />Dynamic Binding<br />Threading with Task...
Optional and Named Parameters<br />
?Quiz<br />What are 2 issues of this API?<br />
Covariance and Contravariance<br />
?Quiz<br />What is wrong with this code?<br />
Covariance Defined<br />Let’s say S is subtype of B and GT is a generic type<br />GT<S> behaves like subtype of GT<B> on a...
?Quiz<br />What is wrong with this code?<br />
Contravariance Defined<br />Let’s say S is subtype of B and GT is a generic type<br />GT<B> behaves like subtype of GT<S> ...
Dynamic Binding<br />
?Quiz<br />Write a method that prints out the Name property of an anonymous object returned by another method<br />
Dynamic binding means…<br />use runtime type for all bindings<br />
?Quiz<br />A method summing Length properties of all parameters, regardless of actual type<br />
?Quiz<br />How to builds C# objects that behave like JavaScript objects, i.e. members can be added at any time?<br />
?Quiz<br />Write a class whose objects can invoke static methods of any particular type<br />Bonus #1: include non-public ...
?Quiz<br />Write a class whose objects can be used as result-caching proxy for the method invocation of any other object<b...
Task Parallel Library (TPL) & PLINQ<br />
?Quiz<br />Write a method calculating Fibonacci number using a thread in thread-pool and returning result to caller<br />
Task Parallelism Features<br />Wait on tasks<br />Support parent-child relationship<br />Exception handling<br />Cancellin...
?Quiz<br />Write 3 methods:<br />Calculate some known Fibonacci numbers<br />Calculate Fibonacci numbers for a range<br />...
Parallel Class<br />Assign delegates to a handful of Task instances, not one-to-one mapping<br />
?Quiz<br />Write a method which calculate some specified Fibonacci numbers and return the sum of them to the caller<br />
Upcoming SlideShare
Loading in …5
×

C# 4.0 and .NET 4.0

4,500 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

C# 4.0 and .NET 4.0

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

×