Type System Unification

This section describes type system unification. All types in C# are derived from 'object'.

C# has an interesting feature called "Type System Unification". In C#, all types, value based or reference based, predefined or user defined, are all derived from "object". The following program shows some interesting elements of this feature:

// Boxing.cs
// Copyright (c) 2006 HerongYang.com. All Rights Reserved.

using System;
class Boxing {
   static void Main() {
      int i = 123;
      object o = i;
      int j = (int) o;
      Console.WriteLine("i      = {0}",i);
      Console.WriteLine("object = {0}",o.ToString());
      Console.WriteLine("j      = {0}",j);
   }
}

Output:

i      = 123
object = 123
j      = 123

Table of Contents

 About This Book

 Introduction of C# (C Sharp)

 Data Type and Variables

 Logical Expressions and Conditional Statements

 Arrays and Loop Statements

Data Type Features

 The "decimal" Data Type

 Simple Types Are "struct" Types

Type System Unification

 Jagged Arrays

 Floating-Point Data Types

 Passing Parameters to Methods

 Execution Environment Class

 Visual C# 2010 Express Edition

 Class Features

 C# Compiler and Intermediate Language

 Compiling C# Source Code Files

 MSBuild - Microsoft Build Engine

 Memory Usages of Processes

 Multithreading in C#

 Async Feature from C# 5

 System.IO.FileInfo Class

 System.Diagnostics.FileVersionInfo Class

 WPF - Windows Presentation Foundation

 Partial Classes and Partial Methods

 Archived Tutorials

 References

 Full Version in PDF/ePUB