this:
using System;
class MyClass
{
private string fs = "ABC-";
public MyClass() { Console.WriteLine("MyClass"); }
public MyClass(string str) { Console.WriteLine(this.fs + str); }
public MyClass(int num) : this() { Console.WriteLine(num); }
public MyClass(int x, int y) : this("XYZ") { Console.WriteLine(x + y); }
}
class Program
{
static void Main()
{
MyClass c1 = new MyClass(); // MyClass
MyClass c2 = new MyClass("EFG"); // ABC-EFG
MyClass c3 = new MyClass(123); // MyClass / 123
MyClass c4 = new MyClass(111, 222); // ABC-XYZ / 333
Console.ReadKey();
}
}
構造函數、屬性、base:
using System;
abstract class Parent
{
private byte FID;
public Parent(byte n)
{
FID = n;
}
public byte Id
{
get { return FID; }
set { FID = value; }
}
}
class Child : Parent
{
public Child(byte MyID) : base(MyID) { }
}
class Program
{
static void Main()
{
Child Rect = new Child(6);
Console.WriteLine(Rect.Id); //6
Rect.Id = 8;
Console.WriteLine(Rect.Id); //8
Console.ReadKey();
}
}