By definition, YES.
That is how it is defined by the specifications!
C# has a unified type system. All C# types, including primitive types
such as int and double, inherit from a single root object type. Thus,
all types share a set of common operations, and values of any type can
be stored, transported, and operated upon in a consistent manner.
Furthermore, C# supports both user-defined reference types and value
types, allowing dynamic allocation of objects as well as in-line
storage of lightweight structures.
Are they implemented differently? Yes, but they are still System.Object
s.
Anywhere in the specifications, in which they refer to object
s or System.Objects
, you can be quite certain that it refers to all types.
What would you expect as the output for the following code?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StackOverflowConsole
{
public class EmptyClass
{
}
public class ReferenceStuff : EmptyClass
{
object a;
}
public class TypeStuff : EmptyClass
{
int a;
}
class Test
{
static void Main()
{
ReferenceStuff r = new ReferenceStuff();
TypeStuff t = new TypeStuff();
if (r is EmptyClass)
{
Console.WriteLine("r is an EmptyClass");
}
if (t is EmptyClass)
{
Console.WriteLine("t is an EmptyClass");
}
}
}
}
Not surprisingly, the output is:
r is an EmptyClass
t is an EmptyClass
Why? Because they are both EmptyClass
objects. EmptyClass
doesn't contribute anything that object
doesn't, but both r and t are of type EmptyClass
nonetheless.