Jon Limjap<br />Microsoft Most Valuable Professional for Visual C#<br />Senior Application Developer, FBM e-Services<br />...
?<br />Do you<br />use C#<br />
?<br />Is C#...<br />static<br />dynamic<br />
static<br />dynamic<br />C# 4.0<br />
Microsoft<br />.NET<br />Dynamic Language Runtime<br />
Why dynamic?<br />
Expressiveness<br />Tell me what to do…<br />…not how to do it<br />
Duck Typing<br />If it quacks, it’s a duck!<br />
Object Runtime Modification<br />Object types can be modified on runtime<br />
Dynamic at compile time<br />dynamic myObj = "blah";<br />System.String at run time<br />
dynamic myObj = "blah";<br />Console.WriteLine(myObj.Contains("lah"));Console.WriteLine(myObj.IndexOf("x"));Console.WriteL...
Requires System.Dynamic<br />dynamic mrFantastic = new ExpandoObject();mrFantastic.Name = "Reed Richards";mrFantastic.Birt...
mrFantastic.SayMyName = new Action(<br />() => Console.WriteLine(mrFantastic.Name));mrFantastic.GetAge = new Func<int>(<br...
jonlimjap@gmail.com<br />http://twitter.com/LaTtEX<br />http://dotnet.kapenilattex.com<br />
Upcoming SlideShare
Loading in...5
×

Dynamics & Object Runtime Composition with C# 4.0

1,260

Published on

A discussion of the new language features of C# 4.0, emphasizing on the dynamic programming capabilities of the language and its ability to define objects at runtime

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

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

No notes for slide

Dynamics & Object Runtime Composition with C# 4.0

  1. 1. Jon Limjap<br />Microsoft Most Valuable Professional for Visual C#<br />Senior Application Developer, FBM e-Services<br />Dynamics & Object Runtime Composition with C# 4.0<br />
  2. 2. ?<br />Do you<br />use C#<br />
  3. 3. ?<br />Is C#...<br />static<br />dynamic<br />
  4. 4. static<br />dynamic<br />C# 4.0<br />
  5. 5. Microsoft<br />.NET<br />Dynamic Language Runtime<br />
  6. 6. Why dynamic?<br />
  7. 7. Expressiveness<br />Tell me what to do…<br />…not how to do it<br />
  8. 8. Duck Typing<br />If it quacks, it’s a duck!<br />
  9. 9. Object Runtime Modification<br />Object types can be modified on runtime<br />
  10. 10. Dynamic at compile time<br />dynamic myObj = "blah";<br />System.String at run time<br />
  11. 11. dynamic myObj = "blah";<br />Console.WriteLine(myObj.Contains("lah"));Console.WriteLine(myObj.IndexOf("x"));Console.WriteLine(myObj.GetType());myObj = new List<int>();Console.WriteLine(myObj.Count);Console.WriteLine(myObj.GetType());<br />Change of type here<br />But no compiler errors!<br />Method signature doesn’t match initial type<br />
  12. 12. Requires System.Dynamic<br />dynamic mrFantastic = new ExpandoObject();mrFantastic.Name = "Reed Richards";mrFantastic.BirthDate = <br />new DateTime(year: 1961, month: 12, day: 2);Console.WriteLine(mrFantastic.Name);Console.WriteLine(mrFantastic.BirthDate);<br />Properties can be added during runtime<br />
  13. 13. mrFantastic.SayMyName = new Action(<br />() => Console.WriteLine(mrFantastic.Name));mrFantastic.GetAge = new Func<int>(<br />() => Convert.ToInt32(<br />(DateTime.Now - mrFantastic.BirthDate).Days <br />/ 365.25));mrFantastic.SayMyName();Console.WriteLine(mrFantastic.GetAge());<br />Methods could be added using Action<T> & Func<T><br />
  14. 14. jonlimjap@gmail.com<br />http://twitter.com/LaTtEX<br />http://dotnet.kapenilattex.com<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×