我是 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());
}
}
我是否正确理解这一点?