全部類型都從System.Object派生安全
class Employee { }
class Employee : System.Object { }
CLR要求全部對象都用new操做符來建立:ui
Employee e = new Employee();
類型轉換:spa
Object o = new Employee(); Employee e = (Employee)o;
Object o = new Object(); if (o is Employee) { Employee e = (Employee)o; }
Object o = new Object(); Employee e = o as Employee; if (e != null) { }
命名空間和程序集:指針
命名空間(namespace)用於對相關的類型進行邏輯性分組。code
namespace ConsoleApplication1 { public sealed class Program { public static void Main(string[] args) { string path=""; System.IO.FileMode fm = new System.IO.FileMode(); System.IO.FileStream fs = new System.IO.FileStream(path,fm); System.Text.StringBuilder sb = new System.Text.StringBuilder(); } } }
using System.IO; using System.Text; namespace ConsoleApplication1 { public sealed class Program { public static void Main(string[] args) { string path=""; FileMode fm = new FileMode(); FileStream fs = new FileStream(path,fm); StringBuilder sb = new StringBuilder(); } } }
C#的using指令還支持另外一種形式,容許爲一個類型 或命名空間建立別名。對象
using WintellectWidget = Wintellect.Widget;
命名空間和程序集的關係:blog