use of object initialization in C#
For Example: Write a program to demonstrate the use of object initialization.
public class
Student
{
public int rollno { get; set; }
public string sname { get; set; }
public int age { get; set; }
public string city { get; set; }
public string sclass { get; set; }
}
class Program
{
static void Main(string[]
args)
{
Student
std = new Student()
{
rollno = 101,
sname = "Nitinkumar",
age = 22,
city = "Barshi",
sclass = "BCA"
};
Console.WriteLine(" Roll No is: {0}", std.rollno);
Console.WriteLine(" Name is: {0}", std.sname);
Console.WriteLine(" Age is: {0}", std.age);
Console.WriteLine(" City is: {0}", std.city);
Console.WriteLine(" Class is: {0}", std.sclass);
Console.ReadLine();
}
}
Output:
Comments
Post a Comment