Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define C# class outside of any namespace

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

like image 723
Adingo Avatar asked Apr 06 '16 19:04

Adingo


People also ask

What is the #define in C?

The #define creates a macro, which is the association of an identifier or parameterized identifier with a token string. After the macro is defined, the compiler can substitute the token string for each occurrence of the identifier in the source file.

What type is a #define in C?

#define in C is a directive which is used to #define alias.

What is C used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is #define in C++ with example?

#define allows you to make text substitutions before compiling the program. Here's an example : #define MAX 70. Before compilation, if the C++ preprocessor finds MAX as one word (so words like MAXIMUM will not be affected), in the source code, it replaces it with the number 70.


1 Answers

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.

like image 118
interesting-name-here Avatar answered Nov 05 '22 10:11

interesting-name-here