所有类默认继承于 System.Object(或叫 Object):
using System;
class MyClass1
{
}
class MyClass2 : Object
{
}
class MyClass3 : System.Object
{
}
class Program
{
static void Main()
{
MyClass1 obj1 = new MyClass1();
MyClass2 obj2 = new MyClass2();
MyClass3 obj3 = new MyClass3();
Console.WriteLine(obj1.ToString()); //MyClass1
Console.WriteLine(obj2.ToString()); //MyClass2
Console.WriteLine(obj3.ToString()); //MyClass3
Console.ReadKey();
}
}
时间: 2025-01-02 07:53:25