// Auto-implemented Property
using System;
class Person
{
//Declaration of auto-implemented property
//No need to declare private data with auto-implemented property
public string Name{get;set;}
//Read Only Auto-Implemented Property
public int Id{get;private set;}
}
class Program
{
static void Main()
{
Person obj=new Person();
//Set Auto Inplemented Property
//obj.Id=1011;
obj.Name="Ankur Bhatnagar";
//Get value of auto-implement Property
Console.WriteLine("Id: {0}, Name: {1}\n",obj.Id,obj.Name);
}
}
No comments:
Post a Comment