You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.1 KiB
C#

4 years ago
/*
* C# Program to Demonstrate Properties of the Class
*/
using System;
class Student
{
private string myName = "N/A";
private int myAge = 0;
public string Name
{
get
{
return myName;
}
set
{
myName = value;
}
}
public int Age
{
get
{
return myAge;
}
set
{
myAge = value;
}
}
public override string ToString()
{
return "Name = " + Name + ", Age = " + Age;
}
public static void Main()
{
Student Student = new Student();
Console.WriteLine("Student details - {0}", Student);
Student.Name = "BOB";
Student.Age = 99;
Console.WriteLine("Student details - {0}", Student);
Student.Age += 1;
Console.WriteLine("Student details - {0}", Student);
Console.ReadLine();
}
}
/*
Student details - Name = N/A, Age = 0
Student details - Name = BOB, Age = 99
Student details - Name = BOB, Age = 100