Saturday, March 1, 2014

Indexer & Object Initializer


This is used to access the object like an array.
Syntax:  object[index]

When you use the above syntax, a field can be accessed.
Syntax for Indexer:

     public  datatype  this[int index]
              return arrayname[index];
             arrayname[index] = value;


Download above code for Demo on Indexer : Download Links

Object Initializer

This concept is introduced in .NET Framework 3.0. This is used to initialize all the fields of an object, without using a constructor.
Classname ObjectName = new Classname() { field1=value1, field2=value2, … };

object initializer

Download above code for Demo on Object Initializer : Download Links

No comments:

Post a Comment