简体   繁体   中英

Define C# class outside of any namespace

是否可以在任何名称空间之外定义 (而不是接口)?

Ran a test and yes you can. Here's my code built off of a Console App:

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");
    }
}

Yes, you can define a class outside of a namespace. Per juharr it ends up in the default global namespace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM