Every single piece of C# I have ever seen is always wrapped 开发者_开发百科is a namespace. Is it possible to include code that is not wrapped in namespace?
You don't have to declare a specific one. Delete the namespace at the top of the script (along with the opening and closing brackets). This will make it part of the global namespace.
From the spec:
Namespaces and types that have no enclosing namespace are members of the global namespace. This corresponds directly to the names declared in the global declaration space.
Namespaces and types declared within a namespace are members of that namespace. This corresponds directly to the names declared in the declaration space of the namespace.
So technically, it is part of a namespace (the global one) even though you didn't specify it.
Of course, you can define types in the global namespace:
using System;
class Program
{
static void Main()
{
Console.WriteLine("I have no namespace");
}
}
精彩评论