【发布时间】:2013-03-05 23:59:58
【问题描述】:
我是 C# 新手,我似乎找不到任何有关这方面的信息,所以我会在这里询问。
必须声明命名空间中的类吗?
using System;
public class myprogram
{
void main()
{
// The console class does not have to be declared?
Console.WriteLine("Hello World");
}
}
如果我不使用命名空间,那么我必须声明一个类
class mathstuff
{
private int numberone = 2;
private int numbertwo = 3;
public int addhere()
{
return numberone + numbertwo;
}
using System;
public class myprogram
{
void main()
{
// the class here needs to be declared.
mathstuff mymath = new mathstuff();
Console.WriteLine(mymath.addhere());
}
}
我理解正确吗?
【问题讨论】:
-
这可以更好地解释here。您应该记住的一件事是,如果您不声明命名空间,则会自动声明全局命名空间。
-
您提供的两个代码示例中的任何一个中都没有提到命名空间。您实际上不是在指静态类和非静态类之间的区别吗?
-
我不认为“声明”这个词意味着你认为它的意思。你认为“声明”是什么意思?
标签: c# class namespaces