Say, before the opening,
In the. NET world, we often hear the word "System.Object is the root of all types, the parent of all types", so much so that I am in "you must know. Net" 8.1 with "all things return to the Pope: System.Object" Such title for the System.Object Award to high honors. So, based on this view there is the following sentence "Does the interface also inherit from System.Object?" "In fact this is just one of those little discussions in the tech group today.
1 origin
In the. NET world, we often hear the word "System.Object is the root of all types, the parent of all types", so much so that I am in "you must know. Net" 8.1 with "all things return to the Pope: System.Object" Such title for the System.Object Award to high honors. So, based on this view there is the following sentence "Does the interface also inherit from System.Object?" "In fact this is just one of those little discussions in the tech group today.
"Interface also inherits from Object" is based on the following two points of view:
Opinion one:
An interface is also a class in nature, since the interface type is compiled in the IL and is identified as. class, and since it is a class it is inevitable that it eventually inherits from System.Object.
Point two:
If you have the following interface and the type of implementation interface:
// Release : code01, 2009/03/04
// Author : Anytao, http://www.anytao.com
// List : IObjectable.cs
public interface IObjectable
{
}
// Release : code02, 2009/03/04
// Author : Anytao, http://www.anytao.com
// List : MyObject.cs
public class MyObject : IObjectable
{
}
Then, for the Iobjectable object, the following call is possible:
// Release : code03, 2009/03/04
// Author : Anytao, http://www.anytao.com
// List : Program.cs
class Program
{
static void Main(string[] args)
{
IObjectable obj = new MyObject();
//Call Object instance methods
obj.ToString();
//Call Object static methods
IObjectable.Equals(null, null);
}
}
Obviously, iobjectable type variable obj can access instance method ToString () and virtual method Equals that exist in System.Object, and of course several other public services are no exception: GetType (), Equals (), GetHashCode (), ReferenceEquals (), can also infer clues to the interface access to the object method.
Admittedly, part of the reasoning above is completely correct, but unfortunately led to the wrong answer, so in this article I will definitely find out: interface does not inherit from the reason and principle of object. For a deep discussion of the nature of the interface, refer to the detailed analysis of the. NET 1.5 "You Must Know", "Topsy Interface" and 7.4 "object-oriented programming: Interfaces and abstract classes."