Dynamic in C# 4.0

1,028 views

Published on

C# 4.0 allows dynamic programming. This presentation explains how this works.

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

  • Be the first to like this

No Downloads
Views
Total views
1,028
On SlideShare
0
From Embeds
0
Number of Embeds
158
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Dynamic in C# 4.0

  1. 1. Dynamic in .NET 4- Benefits of dynamic languages- Dynamic language Runtime (DLR)- Dynamic Objects- Coding without dynamic- Comparing dynamic with object andvar
  2. 2. Benefits of Dynamic Languages• Support for both top-down and bottom-up development. In top-down you call functions that are not implemented yet.• Easier refactoring and code modifications as you do not have to change static types declarations.• The ability to use rapid feedback loop (REPL, or read-evaluate-print loop).
  3. 3. Dynamic Language Runtime• Simplifies porting dynamic languages to the .NET framework.• Enables dynamic features in statically types languages.• Enables sharing of libraries and objects.• Provides fast dynamic dispatch and invocation.
  4. 4. Dynamic Objects• Implement their own binding• The DLR caches and optimises
  5. 5. Coding Without DynamicCalculator calc = GetCalculator();int sum = calc.Add(10, 20);object calc = GetCalculator();Type calcType = calc.GetType();object res = calcType.InvokeMember(“Add”,BindingFlags.InvokeMethod, null, new object[]{10, 20});int sum = Convert.ToInt32(res);
  6. 6. Problems with Dynamic• No compiler-time checking• No intelliSense support
  7. 7. objectobject: root type in .NET class library. You need explicit cast to do type specific operation.object obj = 10;obj = (int) obj + 5;
  8. 8. varvar: Is often used with LINQ. The variable type is inferred from the initialization string at compile time. Var is not a type.var v = 10;v = v + 5;v = “Test”; // ERROR

×