C# 4.0 and .NET 4.0
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

C# 4.0 and .NET 4.0

on

  • 4,778 views

 

Statistics

Views

Total Views
4,778
Views on SlideShare
2,344
Embed Views
2,434

Actions

Likes
0
Downloads
65
Comments
0

7 Embeds 2,434

http://www.buunguyen.net 2335
http://buunguyen.net 82
http://sotayblog.com 7
http://www.slideshare.net 5
http://webcache.googleusercontent.com 3
http://static.slidesharecdn.com 1
http://translate.googleusercontent.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

C# 4.0 and .NET 4.0 Presentation Transcript

  • 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?
  • 5. Covariance and Contravariance
  • 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
  • 10. Dynamic Binding
  • 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