Home > Best Practices of ASP.Net, Dynamic Features in C# > Instantiate Anonymous Generic List in C#

Instantiate Anonymous Generic List in C#

Sometimes we need anonymous objects in our day to day programming. I used anonymous types in my LINQ queries but I never instantiated an anonymous generic list, I mean I never needed to do it. But now I needed and found an easy way to do it. So if you need it you can enjoy 🙂

         /// <summary>
        /// Returns geo-location of cities.        
        /// </summary>
        /// <returns></returns>
        internal List<dynamic> GetCitiesGeoLocation()
        {
            List<dynamic> cities = new List<dynamic>(){
                new { Name="Lahore", Latitude ="31.5497N", Longitude="74.3436E" },
                new { Name="London", Latitude ="51.5072N", Longitude="0.1275W" },
                new { Name ="Kansas City", Latitude ="39.0997N", Longitude ="94.5783W"}
            };

            return cities;
        }
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