using System;
class Student
{
// Declare a Code property of type string
private string iCode = "Nothing";
public string Code
{
get
{
return iCode;
}
set
{
iCode = value;
}
}
// Declare a Name property of type string
private string iName = "Alfread";
public string Name
{
get
{
return iName;
}
set
{
iName= value;
}
}
// Declare a Age property of type int:
private int iAge= 15;
public int Age
{
get
{
return iAge;
}
set
{
iAge = value;
}
}
public override string ToString()
{
return "Code = " + iCode+", Name = " + iName + ", Age = " + iAge ;
}
public static void Main()
{
// Create a new Student object:
Student s = new Student();
// Setting code, name and the age of the student
s.Code = "001";
s.Name = "Zara";
s.Age = 9;
Console.WriteLine("Student Info: {0}", s);
//let us increase age
s.Age += 1;
Console.WriteLine("Student Info: {0}", s);
Console.ReadKey();
}
}
class Student
{
// Declare a Code property of type string
private string iCode = "Nothing";
public string Code
{
get
{
return iCode;
}
set
{
iCode = value;
}
}
// Declare a Name property of type string
private string iName = "Alfread";
public string Name
{
get
{
return iName;
}
set
{
iName= value;
}
}
// Declare a Age property of type int:
private int iAge= 15;
public int Age
{
get
{
return iAge;
}
set
{
iAge = value;
}
}
public override string ToString()
{
return "Code = " + iCode+", Name = " + iName + ", Age = " + iAge ;
}
public static void Main()
{
// Create a new Student object:
Student s = new Student();
// Setting code, name and the age of the student
s.Code = "001";
s.Name = "Zara";
s.Age = 9;
Console.WriteLine("Student Info: {0}", s);
//let us increase age
s.Age += 1;
Console.WriteLine("Student Info: {0}", s);
Console.ReadKey();
}
}
No comments:
Post a Comment