1. Dynamic in .NET 4
- Benefits of dynamic languages
- Dynamic language Runtime (DLR)
- Dynamic Objects
- Coding without dynamic
- Comparing dynamic with object and
var
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. 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.
5. Coding Without Dynamic
Calculator 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);
7. object
object: root type in .NET class library. You need
explicit cast to do type specific operation.
object obj = 10;
obj = (int) obj + 5;
8. var
var: 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