ARTICLE

Dynamic Programming in .NET 4.0

Posted by BALAMURUGAN ALAGUMALAI Articles | C# Language October 13, 2009
Dynamic programming is new addition to .NET 4.0 and C# 2010.
Reader Level:

C# 4.0 supports dynamic programming by introducing new dynamic typed objects. The type of these objects is resolved at run-time instead of at compile-time. The keyword tells the compiler that everything to do with the object, declared as dynamic, should be done dynamically at the run-time using Dynamic Language Runtime(DLR)


The main advantages of this dynamic programming are it provides more flexibility to developers.

Example:

dynamic num = Getnum();

dynamic str = GetString();

Console.WriteLine("Your number is " + num);

Console.WriteLine("Your string is " + str);

Console.Read();

 

private static string GetString()

{

    return "Welcome";

}

private static int Getnum()

{

    return 1;

}



Note: We use var keyword but the main different between the both is var resolved at compile time and dynamic resolved at runtime.

Login to add your contents and source code to this article
Article Extensions
Contents added by Mahesh Chand on Oct 14, 2009

If you need more details on dynamic types and dynamic programming, here are some more detailed references:

Here is a link on Dynamic Language Runtime:


Cheers!
post comment
     
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts