New in framework 4 - dynamic object

Below the previous post on framework 4 (Parallel) - time will demonstrate the new type object - "dynamic".

Dynamic object is built at runtime.
Unlike the previous version of the framework, when we received the object VAR - VAR built during Compilation, so that in fact we knew the type of object VAR in advance.
Dynamic does not know it's like you until it actually materialize.

Let's see an example


Please note that varObject already during Compilation does not give us continue to work because of that string is not int.
However, dynamicObject passes Compilation.


Here is the correct code - passing Compilation:

using System;
using
 System.Collections.Generic;
using
 System.Linq;
using
 System.Text;
namespace
 ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var varObject = 1;
            Console.WriteLine("var object = {0}. the type is {1}",varObject,varObject.GetType());
            //var varObject = "1";
            //Console.WriteLine "var object = {0}. the type is {1}", varObject, varObject.GetType());
            dynamic dynamicObject = 1;
            Console.WriteLine("dynamic object = {0}. the type is {1}", dynamicObject, dynamicObject.GetType());
            dynamicObject = "1";
            Console.WriteLine("dynamic object = {0}. the type is {1}", dynamicObject, dynamicObject.GetType());
            Console.ReadLine();
        }
    }
}

Yours,
Roi

Comments

Popular posts from this blog

A sharepoint list view of the current month

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters

Export SharePoint 2010 List to Excel with PowerShell