Object là lớp cơ sở cho tất cả kiểu dữ liệu C#. Object Type là base class tối thượng trong CTS (Common Type System). object là alias của System.Object.
Chuyển value type -> object type gọi là boxing. Ngược lại (object -> value type) gọi là unboxing.
Ví dụ
using System;
using System.IO;
namespace Demo {
class objectClass {
public int x = 56;
}
class MyApplication {
static void Main() {
object obj;
obj = 96; // boxing
Console.WriteLine(obj);
obj = new objectClass();
objectClass newRef;
newRef = (objectClass)obj; // unboxing
Console.WriteLine(newRef.x);
}
}
}