Your SlideShare is downloading. ×
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Community Tech Days C# 4.0
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Community Tech Days C# 4.0

1,427

Published on

My Community Tech Days presentation on C# 4.0

My Community Tech Days presentation on C# 4.0

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,427
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
41
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. C# 4.0 Language Enhancements
    Sankarsan Bose
    11th October 2009
  • 2. Agenda
    • Journey of C#
    • 3. Current Trends
    • 4. C# 4.0 Features
    • 5. Dynamic Objects
    • 6. Named And Optional Parameters
    • 7. Covariance And Contravariance
    • 8. Improved COM InterOp
  • Journey of C#
    ???
    Functional + LINQ
    Generics
    Static Language + Managed Code
  • 9. Current Trends
    C#
  • 10. C# 4.0 Features
    • Dynamic Programming
    • 11. Optional and Named Parameters
    • 12. Co- and Contra-variance
    • 13. Improved COM Interoperability
  • Dynamic Programming
    Ruby Code Sample
    • No type is defined
    • 14. Stores string value
    • 15. “+” operator concatenates
    • 16. Assigned int values
    • 17. “+” operator adds
    Type Determined At Runtime Based On Type Of Value Stored
  • 18. Dynamic Programming
    Ruby Code Sample
    • Both classes define “print”
    • 19. Exactly same signature
    • 20. No type defined for parameter “p”
    • 21. Any object supporting method “print” is a valid input
    • 22. This is called “Duck Typing”
    Method To Be Invoked Is Decided At Runtime
  • 23. Dynamic Programming
    Dynamic Method Dispatch in C# (Before 4.0)
    Both are staticallytyped as IOfficeDocument
  • 24. Dynamic Programming
    Dynamically Typed Objects in C# 4.0
    • New keyword “dynamic”
    • 25. Statically Typed as “dynamic”
    • 26. Actual type determined at runtime
    Dynamic Method Invocation
  • 27. Dynamic Programming
    Pros
    • No risk of brittle class hierarchy
    • 28. Need not implement all methods of interface
    • 29. More flexible , highly productive
    Cons
    • Developer needs thorough understanding of codebase
    • 30. Misuse might lead to poor maintainability
  • Dynamic Programming
    Demo
  • 31. Dynamic Programming
    C# is a statically typedlanguage
    How we are making it dynamic ???
    Here Comes DLR
    Dynamic Language Runtime
  • 32. Dynamic Programming
    DLR is additional libraries to fit the dynamic languages into the CLR
    • Store program/code as data
    • 33. Caching mechanism for dynamic call
    • 34. Provide language specific support
  • Dynamic Programming
    Class Generated Under The Hood
    • CallSite is created before method call
    • 35. Actual method call is delegated to CallSite
    • 36. Compiler Generated Class
    • 37. Reference to CallSite
  • 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
  • 38. Optional & Named Parameters
    “b” & “c” are nullable & optional
    Calling code has to pass null value
    This is an issue for large no of parameters
  • 39. 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
  • 40. 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
  • 41. Optional & Named Parameters
    Demo
  • 42. 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
  • 43. 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”
  • 44. 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”
  • 45. Covariance & Contravariance
    Covariance in Arrays (Existing in C# )
    This covariance is allowed
    This code compiles
    But throws Runtime Exception
  • 46. 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
  • 47. Covariance & Contravariance
    Covariance in Generic Types of C# 4.0
    This covariance is allowed
    public interface IEnumerable<out T> : IEnumerable{IEnumerator<T> GetEnumerator();}
  • 48. 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);}
  • 49. Covariance & Contravariance
    Demo
  • 50. Improved COM InterOp
    • Optional “ref” modifier
    • 51. Optional and named parameters
    • 52. Dynamic objects
    • 53. No additional type casts needed
    • 54. InterOp type embedding (“No PIA”)
  • Improved COM InterOp
    Pass Parameters without using “ref”
  • 55. Improved COM InterOp
    Take advantage of named parameters & optional arguments
  • 56. Improved COM InterOp
    Take advantage of named parameters & optional arguments
  • 57. Improved COM InterOp
    Demo
  • 58. Journey of C# - Revisited
    Dynamic
    Functional + LINQ
    Generics
    Static Language + Managed Code
  • 59. Thank You
  • 60. References
    • http://channel9.msdn.com/shows/Going+Deep/Inside-C-40-dynamic-type-optional-parameters-more-COM-friendly/
    • 61. http://channel9.msdn.com/posts/Charles/C-40-Meet-the-Design-Team/
    • 62. http://channel9.msdn.com/shows/Going+Deep/Expert-to-Expert-Anders-Hejlsberg-The-Future-of-C/
    • 63. http://channel9.msdn.com/pdc2008/TL16/

×