Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 09-07-2009
Member
 
Join Date: May 2008
Posts: 3,971
C# 4.0 Dynamic

One of the core features introduced in C# 4.0 is called Dynamic Lookup which allows a unified approach to invoking things dynamically. C# 3.0 was all about Language Integrated Query (LINQ) and C# 4.0 is all about dynamic programming. C# 4.0 brings some of flexibility and declarative style of programming to C#. C# 4.0 features a new dynamic keyword that allows you to mix in a bit of late-bound code in the midst of your otherwise statically typed code. It is used as a data type in much the same way the var keyword is used. The biggest reason is that it allows a C# program to use dynamic dispatch to more naturally create objects coming from a dynamic language.

As an example, suppose you have a method like this:
Code:
public dynamic myMethod()
{
    // Get your work done here...
}
and you call it as:

Code:
dynamic callMethod = myMethod();
callMethod.Do("Your Job");
The C# 4.0 compiler allows you to call a method with any name and any arguments because callMethod is declared as "dynamic".
Reply With Quote
  #2  
Old 09-07-2009
XSI XSI is offline
Member
 
Join Date: May 2008
Posts: 271
Re: C# 4.0 Dynamic

Does that means C# 4.0 is lacking the statically typed language? Because if you don't mention the datatype of a variable, there should be an error saying data type is missing. If C# 4.0 gives us so much of flexibility then no one will mention any data type and will simply use "dynamic" keyword.
Reply With Quote
  #3  
Old 09-07-2009
Member
 
Join Date: May 2008
Posts: 3,971
Re: C# 4.0 Dynamic

Well, no. The basic idea behind this is to provide flexibility to write C# code which talks to objects (or APIs). The "dynamic" operand differs compile-time declaration with run-time. At run-time the "dynamic" is replaced with the actual datatype. So if a variable is assigned a value of "1", the datatype will automatically be converted to "System.Int32".
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "C# 4.0 Dynamic"
Thread Thread Starter Forum Replies Last Post
What are the Dynamic Signatures? Mei-Xiu Software Development 6 13-05-2010 11:01 PM
I need some details about Dynamic DNS Bansi_WADIA Technology & Internet 4 16-01-2010 05:00 AM
Dynamic Overclocking wazzeledozzle Overclocking & Computer Modification 6 06-12-2008 05:55 PM
How can I have a dynamic IP address Spectacle Networking & Security 4 21-10-2008 06:50 PM
Help me redirecting dynamic IP Maximus() Networking & Security 3 04-08-2008 03:25 PM


All times are GMT +5.5. The time now is 05:00 AM.