using System.Reflection;
QTMCsharp namespace
{
class TestCsharp
{
static void Main (string [] args)
{
Console.WriteLine ("Property" in C # ");
Console.WriteLine ("------------------------------------");
// create a student doi tuong
Student s = new Student ();
// Learn the code, name and age for Student
s.Code = "001";
s.Name = "Minh Chinh";
s.Age = 21;
Console.WriteLine ("Student Information: {0}", s);
// fly an extra age 1
s.Age + = 1;
Console.WriteLine ("Student Information: {0}", s);
Console.ReadLine ();
Console.ReadKey ();
}
}
}
If you do not use the Console.ReadKey () command; then the program will run and finish (so fast that you can not see the results). This command allows us to see the results more clearly.
Compiling and running the above C # program will produce the following results:
An Abstract class can have an abstract attribute, which should be implemented in the inheritance class. The following program illustrates this:
Create 3 classes named respectively Person, Student, TestCsharp as follows:
Abstract class Person :
sing System ; namespace QTMCsharp { public abstract class Person { public abstract string Name { get ; set ; } public abstract int Age { get ; set ; } } }
Student Class:
dùng System;
QTMCsharp namespace
{
class Student: Person
{
private string code = "N / A";
private string name = "N / A";
private int age = 0;
// declare the code Code has string:
public string Code
{
get
{
return code;
}
set
{
code = value;
}
}
// declare the name of the string name:
public override string Name
{
get
{
return name;
}
set
{
name = value;
}
}
// Declare Age code has int int:
public override int Age
{
get
{
return age;
}
set
{
age = value;
}
}
public override string ToString ()
{
return "MSSV =" + Code + ", Ho ten =" + Name + ", Tuoi =" + Age;
}
}
}
Class TestCsharp
dùng System;
using System.Reflection;
QTMCsharp namespace
{
class TestCsharp
{
static void Main (string [] args)
{
Console.WriteLine ("Property" in C # ");
Console.WriteLine ("------------------------------------");
// create a student doi tuong
Student s = new Student ();
// Learn the code, name and age for Student
s.Code = "001";
s.Name = "Minh Chinh";
s.Age = 21;
Console.WriteLine ("Student Information: {0}", s);
// fly an extra age 1
s.Age + = 1;
Console.WriteLine ("Student Information: {0}", s);
Console.ReadLine ();
Console.ReadKey ();
}
}
}
Compiling and running the above C # program will produce the following results:
According to Tutorialspoint
Previous lesson: Print pages in JavaScript
Next article: Objects in JavaScript