Program Related To Automatic Property And Object Initializer Feature
========================================================================
ProgramWithOutAutomaticProperties But Use Object Initializer
========================================================================
using System;
class Room
{
private int _length, _breadth;
public int Length{
set{_length = value;}
get{return _length;}
}
public int Breadth{
set{_breadth = value;}
get{return _breadth;}
}
}
class ProgramWithOutAutomaticProperties
{
static void Main()
{
Room obj = new Room{Length = 10, Breadth=30};
int Area = obj.Length * obj.Breadth;
Console.WriteLine("Area is " + Area);
Console.WriteLine();
}
}
OUTPUT
========================================================================
ProgramWithAutomaticProperties But Use Object Initializer
========================================================================
using System;
class Room
{
public int Length{set;get;}
public int Breadth{set;get;}
}
class ProgramWithAutomaticProperties
{
static void Main()
{
Room obj = new Room{Length = 10, Breadth=30};
int Area = obj.Length * obj.Breadth;
Console.WriteLine("Area is " + Area);
Console.WriteLine();
}
}
========================================================================
OUTPUT
Program Related To Automatic Property And Object Initializer Feature
Reviewed by Baljeet Singh
on
10:08
Rating:
No comments: