Adingo
Adingo

Reputation: 53

Define C# class outside of any namespace

Is it possible to define a class (not interface) outside of any namespace?

Upvotes: 5

Views: 2705

Answers (1)

interesting-name-here
interesting-name-here

Reputation: 1890

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.

Upvotes: 7

Related Questions