Answer: The Object initializers are the features for programming concepts which was introduced in C#.Net.
The aim of using Object Initializers is to intializing the accessible fields or properties
of an object without the need to write any parameterized constructor or separate
statements.
Sample:
using System;
class Student
{
int rollno;
string stdName;
static void Main()
{
Student s = new Student() { rollno=1,stdName="Ramesh" }; //Object Initializer
}
}
Asked In: Many Interviews |
Alert Moderator