全部类型都从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