Saturday, March 1, 2014

Indexer & Object Initializer

Indexer

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]
       {
         get
            {
              return arrayname[index];
            }
         set
           {
             arrayname[index] = value;
            }
       }

Indexer

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.
Syntax:
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

Flag Counter