#950 – C# Has a Unified Type System

C# has a unified type system, which means that all types inherit, directly or indirectly, from object (System.Object).  This includes both reference and value types.  It also includes all primitive types, like int and bool, as well as every type provided in the .NET Framework and every custom type that you define.

Because every type inherits from object, you can call any of the System.Object methods (e.g. Equals and ToString) on an instance of any type.

            Dog d = new Dog("Bob", 5);
            int i = 42;
            bool awake = true;

            Console.WriteLine(d.ToString());
            Console.WriteLine(i.ToString());
            Console.WriteLine(awake.ToString());

950-001

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

2 Responses to #950 – C# Has a Unified Type System

  1. Pingback: Dew Drop – October 11, 2013 (#1,643) | Morning Dew

  2. Pingback: #951 – Not Every Type Derives from object | 2,000 Things You Should Know About C#

Leave a comment