Log in

Previous Entry | Next Entry

Object initializer let us create an instance of a class and assign values to its properties in a single line. Normally we write following things while working with classes and objects.

      1. Create Object of class

        code 1

       2. Assign values to its properties

          code 2

But with object initializer we can do it in single line as follows

        code 3

What does collection initializer do?

Just like Object initializer it will reduce the work of a developer. It will let us create an instance of any collection class and assign one or more elements to it in the same line.

This is how we normally work,

      1. Create instance of collection class.

          code 4

      2. Add elements to it

          code 5

But with collection initializer we can do it in single line.

        code 6

For technical trainings on various topics like WCF, MVC, Business Intelligence, Design Patterns, WPF, TFS and Basic fundamentals feel free to contact SukeshMarla@Gmail.com or visit www.sukesh-marla.com

For more stuff like this, click here. Subscribe to article updates or follow at twitter @SukeshMarla

Also do not forget to visit http://www.questpond.com for step by step, technical video & trainings.
Copy right www.questpond.com

Buy 600+ Real Time Interview Videos

Call +91-22-66752917 or mail us on questpond@questpond.com for more details on C#, .NET, ASP.NET, SQL Server interview question videos.

SQL Server interview question videos

Latest Month

March 2017


Powered by LiveJournal.com