C#代码里没有命名空间“namespace ---{}”但也可以运行,为什么?
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.chs/cpref10/html/P_System_Reflection_ParameterInfo_Attributes.htm
小弟今天在MS帮助文档上看到了下面一段代码,发现里面没有写命名空间,我把它粘贴运行后,一切正常。我不明白为什么没有命名空间程序也能正常运行?下面代码里的两个类又属于谁?若其他项目想要调用这两个类该从哪找?希望各位大侠给个解释,能让小弟拨开迷雾见太阳。谢谢。
using System;
using System.Reflection;
public class MyClass1
{
public int MyMethod(int i, out short j, ref long k)
{
j = 2;
return 0;
}
}
public class ParameterInfo_Attributes
{
public static void Main()
{
// Get the type.
Type myType = typeof(MyClass1);
// Get the method named 'MyMethod' from the type.
MethodBase myMethodBase = myType.GetMethod("MyMethod");
// Get the parameters associated with the method.
ParameterInfo[] myParameters = myMethodBase.GetParameters();
Console.WriteLine("\nThe method {0} has the {1} parameters :",
"ParameterInfo_Example.MyMethod", myParameters.Length);
// Print the attributes associated with each of the parameters.
for (int i = 0; i < myParameters.Length; i++)
Console.WriteLine("\tThe {0} parameter has the attribute : {1}",
i + 1, myParameters[i].Attributes);
Console.ReadKey();
}
}