C#的初学者,Inner类的有作用范围么
我从C#的specification上输入了一段程序
Stack.cs
using System;
namespace Helloworld
{
/// <summary>
/// Stack 的摘要说明。
/// </summary>
public class Stack
{
private Node first=null;
public bool empty()
{
return (first==null);
}
public Object Popup()
{
if(first==null)
{
throw new Exception("Can't popup from an empty stack");
}
else
{
Object temp=first.Value;
first=first.Next;
return temp;
}
}
public void Push(Object o)
{
first=new Node(o,first);
}
public Stack()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
class Node
{
public Node Next;
public Object Value;
public Node(Object Value):this(Value,null){}
public Node(object value, Node next)
{
Next =next;
Value=value;
}
}
}
}
Hello.cs
using System;
namespace Helloworld
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class HelloWorld
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
Console.WriteLine("Hello,world");
Console.WriteLine("Test Stack");
Stack s=new Stack();
for(int i=0;i<10;i++)
{
s.Push(i);
}
while(!s.empty())
{
Console.WriteLine(s.Popup());
}
}
}
}
运行正常。
我的问题是,Node类的写法是嵌在Stack中的,那么我在Hello.cs中是否可以创建Node类的对象呢?