Object Initialization in C#

Create the customer class with the set of properties.

 public class Customer

{

      public Customer()

      {

            //

            // TODO: Add constructor logic here

            //

      }

 

    public string CustomerID { get; set; }

    public string FirstName { get; set; }

    public string LastName { get; set; }

    public string Address { get; set; }

    public string City { get; set; }

    public string State { get; set; }

    public string Country { get; set; }

    public string Mobile { get; set; }

    public string Mail { get; set; }

 

}

 

Initialize the object by the conversional method.

  Customer customer = new Customer();

        customer.CustomerID = "1";

        customer.FirstName = "Senthil";

        customer.LastName = "kumar";

        customer.Address = "Bangalore";

        customer.City = "Bangalore";

        customer.State = "Karnataka";

        customer.Country = "India";

        customer.Mobile = "9989898989";

        customer.Mail = "[email protected]";

 

 

Object Initialization in 3.0

        //Object Initialization

        Customer cusomer = new Customer

        {

            CustomerID="1",FirstName="Senthil",LastName="Kumar",Address="Bangalore",City="Bangalore",State="Karnataka",Country="India",Mobile="9998989898",Mail="[email protected]"

           

        };