Home > Development > .NET 4 Dynamic Types with Anonymous Types

.NET 4 Dynamic Types with Anonymous Types


A post i wrote a while ago on pain with anonymous types has been totally rectified with the use of dynamic. How cool is the following code ๐Ÿ™‚

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace V4Features
{
    class Program
    {
        static void Main(string[] args)
        {
            var customer = new
            {
                Id = 1,
                Name = "Blair Davidson"
            };

            List<dynamic> list = new List<dynamic> {customer};

            Console.WriteLine("Count: {0}", list.Count);

            Console.WriteLine(list.GetType().FullName);
            Console.ReadKey();
        }
    }
}

Not sure where I will use this yet but i will help work around a some hard issues im sure ๐Ÿ™‚

Blair…

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: