c# - 在任何命名空间之外定义 C# 类

标签 c# class namespaces

是否可以在任何命名空间之外定义一个(不是接口(interface))?

最佳答案

运行测试,是的,你可以。这是我基于控制台应用程序构建的代码:

using System;
using System.Text;

namespace With_Console_App
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("This will output something: ");
            Console.ReadLine();
            some.Print();
            Console.ReadLine();
        }
    }
}

class some
{
    public static void Print()
    {
        Console.WriteLine("something");
    }
}

是的,您可以在命名空间之外定义一个类。根据 juharr,它最终位于默认的全局命名空间中。

关于c# - 在任何命名空间之外定义 C# 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36460263/

相关文章:

javascript - Angular JS 脚本应用程序始终使用 Wcf 服务返回 True

python - 为对象添加错误处理的最佳位置?

C++ 复制构造函数和运算符

php - 在composer中插入类的路径,所以我可以在php的 "use"中删除它

codeigniter - 模式创建时的 Doctrine + CodeIgniter : after generate entities with namespace, "cannot redeclare class"

c# - 托管Cuda : IllegalAddress; While Executing a Kernel

c# - 如何在我的 Linux Web 服务器上运行 .dll 文件

c# - 监视文件夹并查找文件是否在 Windows 应用程序中打开

java.lang.ClassCastException 套接字 readObject

PHP 是命名空间或全局的包含类的一部分吗?