.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Code Snippets >> File Operation >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Complex Object Initialzer

Posted By:Mahesh       Posted Date: March 29, 2011    Points: 40    Category: File Operation    URL: http://www.dotnetspark.com  

Following code demonstrates how the objects (sub objects) can be dynamically initiallised.

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

namespace objectinitialzerwithcomplex2
    class Program
        static void Main(string[] args)
            //Object Initializer with complex type

            Person person = new Person
                FirstName = "Mahaling",
                LastName = "Khubba",
                Age = 27,
                Add = new Address
                    City = "Latur",
                    State = "Maharashtra",
        public class Person
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public int Age { get; set; }
            public Address Add { get; set; }

        public class Address
            public string City { get; set; }
            public string State { get; set; }



Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend