顶层类是包含套嵌类的类。
顶层类与套嵌类的关系十分密切,或套嵌类仅供顶层类使用时才推荐使用套嵌起来的方式。
using System; namespace Acme.Collections { public class Stack { Entry top; public void Push(object data) { top = new Entry(top, data); } public object Pop() { if (top == null) throw new InvalidOperationException(); object result = top.data; top = top.next; return result; } class Entry { public Entry next; public object data; public Entry(Entry next, object data) { this.next = next; this.data = data; } } } }