Object initialization ASP.net

What is Object initialization:

Object initializes are used to initialize or store the required data in to data field at a class when we create object to the class.

At the time of creating object only we use delimiters to initializes the data into object data fields like

Emp obj=new Emp () {empid=10, ename=”Raju”, address=”hyd”, age=23};

Example with object initializes:

Name space CA sample

{

Class employee

{

Public int empid,age;

Public string ename, add;

}

Class example4

{

Employee obj=new employee () { empid=101,enames=”Raju”,add=”hyd”,age=23};

c.w.l (“employee details are:-”);

c.w.l (“Id is:-”obj.empid);

c.w.l (“Name is:-“obj.ename);

c.w.l (“Address is:-”obj.address);

c.w.l (“age is:-”obj.age);

c.Read();

}

}

}

Interested in ASP.net Training? Enroll now for FREE demo on ASP.net Training.

Example of object initialize with Auto implemented properties:

Name space CA sample

{

Class employee1

{

Public int pemp id

{

Set;

Get;

}

Public string pename

{

Set;

Get;

}

Public string paddress

{

Set;

Get;

}

Public int page

{

Set;

Get;

}

}

Class employee 5

{

Static void main ()

{

Employee 1 obj  = new Employee1 {p emp id = 101, p ename ‘Raju’ p address = ‘’ hyd, page - 23};

C.W.L (“Id is :-”  obj. p emp id);

C.W.L (“Name is :-”  obj. p ename);

C.W.L (“Address is :-”  obj. p Address);

C.W.L (“Age is :-”  obj. page);

}

}

}

For indepth understanding click on