#775 – Copying an Array of Anonymously-Typed Objects

You can create an implicitly-typed array that contains an array of anonymously-typed objects.

            var movies = new[] {
                new { Title = "North By Northwest", Year = 1959, Director = "Alfred Hitchcock" },
                new { Title = "Zelig", Year = 1983, Director = "Woody Allen" },
                new { Title = "King Kong", Year = 2005, Director = "Peter Jackson" }};

If you’d like to create a copy of this array, you can use the Clone method.  This will create a new array of the same type and copy all of the anonymously-typed elements to the new array.

            var copy = movies.Clone();
Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #775 – Copying an Array of Anonymously-Typed Objects

  1. Pingback: Dew Drop – February 7, 2013 (#1,495) | Alvin Ashcraft's Morning Dew

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 )

Connecting to %s

%d bloggers like this: