Below is the small example of get() and set() properties in C#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace studentpropertyDemo
{
class student
{
int rno;
string name,std;
float per;
public int studrno
{
set
{
rno = value;
}
get
{
return rno;
}
}
public float studper
{
set
{
per = value;
}
get
{
return per;
}
}
public string studname
{
set
{
name = value;
}
get
{
return name;
}
}
public string studstd
{
set
{
std = value;
}
get
{
return std;
}
}
}
class Program
{
static void Main(string[] args)
{
student s1 = new student();
s1.studrno = 101;
s1.studname = "Vinayak";
s1.studstd = "twelth";
s1.studper = 91.91f;
Console.WriteLine("roll no={0}\n name={1}\nstd={2}\nper={3}", s1.studrno, s1.studname, s1.studstd, s1.studper);
Console.ReadLine();
}
}
}
Comments
Post a Comment