Community Tech Days C# 4.0

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Community Tech Days C# 4.0 - Presentation Transcript

    1. C# 4.0 Language Enhancements
      Sankarsan Bose
      11th October 2009
    2. Agenda
      • Journey of C#
      • Current Trends
      • C# 4.0 Features
      • Dynamic Objects
      • Named And Optional Parameters
      • Covariance And Contravariance
      • Improved COM InterOp
    3. Journey of C#
      ???
      Functional + LINQ
      Generics
      Static Language + Managed Code
    4. Current Trends
      C#
    5. C# 4.0 Features
      • Dynamic Programming
      • Optional and Named Parameters
      • Co- and Contra-variance
      • Improved COM Interoperability
    6. Dynamic Programming
      Ruby Code Sample
      • No type is defined
      • Stores string value
      • “+” operator concatenates
      • Assigned int values
      • “+” operator adds
      Type Determined At Runtime Based On Type Of Value Stored
    7. Dynamic Programming
      Ruby Code Sample
      • Both classes define “print”
      • Exactly same signature
      • No type defined for parameter “p”
      • Any object supporting method “print” is a valid input
      • This is called “Duck Typing”
      Method To Be Invoked Is Decided At Runtime
    8. Dynamic Programming
      Dynamic Method Dispatch in C# (Before 4.0)
      Both are staticallytyped as IOfficeDocument
    9. Dynamic Programming
      Dynamically Typed Objects in C# 4.0
      • New keyword “dynamic”
      • Statically Typed as “dynamic”
      • Actual type determined at runtime
      Dynamic Method Invocation
    10. Dynamic Programming
      Pros
      • No risk of brittle class hierarchy
      • Need not implement all methods of interface
      • More flexible , highly productive
      Cons
      • Developer needs thorough understanding of codebase
      • Misuse might lead to poor maintainability
    11. Dynamic Programming
      Demo
    12. Dynamic Programming
      C# is a statically typedlanguage
      How we are making it dynamic ???
      Here Comes DLR
      Dynamic Language Runtime
    13. Dynamic Programming
      DLR is additional libraries to fit the dynamic languages into the CLR
      • Store program/code as data
      • Caching mechanism for dynamic call
      • Provide language specific support
    14. Dynamic Programming
      Class Generated Under The Hood
      • CallSite is created before method call
      • Actual method call is delegated to CallSite
      • Compiler Generated Class
      • Reference to CallSite
    15. Dynamic Programming
      CLR – DLR Interaction
      Runtime
      Compile Time
      CLR
      Compiler injects call to DLR CallSite
      C# Source Code
      MSIL Code
      Call is delegated to DLR Call Site Cache
      DLR
      CallSite Cache
      Determines type Determines method
      Returns Expression Tree
      Call Runtime Binder for Cache miss
      C# Runtime Binder
    16. Optional & Named Parameters
      “b” & “c” are nullable & optional
      Calling code has to pass null value
      This is an issue for large no of parameters
    17. Optional & Named Parameters
      Solution Using Overload in C# (Before 4.0)
      One overload accepts only “a”
      Another accepts “a” & “b”
      This is not possible
      Signature clash with the previous method
    18. Optional & Named Parameters
      Solution Using C# 4.0
      Optional Parameter with Default Value
      Optional Parameter omitted in the call
      Method call with parameter names
      Position reversed
    19. Optional & Named Parameters
      Demo
    20. Covariance & Contravariance
      Subclass
      Ellipse
      Circle
      As per Liskov Substitution Principle(LSP):
      Any program which expects an object of Ellipse
      Will function without any change with an object of Circle
      Covariance – Type substitution as per LSP
      Contravariance – Type substitution reverse to LSP
    21. Covariance & Contravariance
      Delegate Covariance in C# (Already Present)
      Func<Base> is a delegate which returns type “Base”
      Func<Base> can be replaced by function with return type “Derived”
    22. Covariance & Contravariance
      Delegate Contravariance in C# (Already Present)
      Func<Derived , Object> is a delegate which accepts type “Derived”
      Func<Base> can be replaced by function which accepts type “Base”
    23. Covariance & Contravariance
      Covariance in Arrays (Existing in C# )
      This covariance is allowed
      This code compiles
      But throws Runtime Exception
    24. Covariance & Contravariance
      Invariance in Generic Types(Existing in C# )
      This covariance is not allowed
      This code will not compile
      Before C# 4.0 Generic Types are Invariant
    25. Covariance & Contravariance
      Covariance in Generic Types of C# 4.0
      This covariance is allowed
      public interface IEnumerable<out T> : IEnumerable{IEnumerator<T> GetEnumerator();}
    26. Covariance & Contravariance
      Contravariance in Generic Types of C# 4.0
      This Contravariance is allowed
      public interface IComparer<in T>{ public int Compare(T left, T right);}
    27. Covariance & Contravariance
      Demo
    28. Improved COM InterOp
      • Optional “ref” modifier
      • Optional and named parameters
      • Dynamic objects
      • No additional type casts needed
      • InterOp type embedding (“No PIA”)
    29. Improved COM InterOp
      Pass Parameters without using “ref”
    30. Improved COM InterOp
      Take advantage of named parameters & optional arguments
    31. Improved COM InterOp
      Take advantage of named parameters & optional arguments
    32. Improved COM InterOp
      Demo
    33. Journey of C# - Revisited
      Dynamic
      Functional + LINQ
      Generics
      Static Language + Managed Code
    34. Thank You
    35. References
      • http://channel9.msdn.com/shows/Going+Deep/Inside-C-40-dynamic-type-optional-parameters-more-COM-friendly/
      • http://channel9.msdn.com/posts/Charles/C-40-Meet-the-Design-Team/
      • http://channel9.msdn.com/shows/Going+Deep/Expert-to-Expert-Anders-Hejlsberg-The-Future-of-C/
      • http://channel9.msdn.com/pdc2008/TL16/
    SlideShare Zeitgeist 2009

    + SANKARSAN BOSESANKARSAN BOSE Nominate

    custom

    89 views, 0 favs, 1 embeds more stats

    My Community Tech Days presentation on C# 4.0

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 89
      • 79 on SlideShare
      • 10 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 2
    Most viewed embeds
    • 10 views on http://codingndesign.com

    more

    All embeds
    • 10 views on http://codingndesign.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags