36
Reply

Can class exists without namespace

MD SHAMSE ALAM

MD SHAMSE ALAM

9y
4.3k
0
Reply

    It is impossible to create a class without having a namespace . But in asp.net we can create a class without having a namespace , in this case asp.net compiler will add a namespace called global under which the classes will be added . For testing this open an asp.net website create class with the name Class1 in a.aspx.cs file , create one more file with the same class name that is Class1 . Now try to compile and execute code . You will definitely get an error stating global namespace is already having the class with the name Class1 . Hence it is not possible to create a class without a name space ( incase of asp.net if you skip namespace asp.net will create one for you with the name global )

    Its actually possible to create a class without any namespace in .net. However, it takes the global namespace.

    Yes we can create class without namespace.

    yes.

    yes we can create

    I myself never have seen any classes without namespace, please explain if you have seen class without namespace.

    No, Without Namespace class can never exists.

    Yes

    Yes

    Yes

    Yes

    Yes

    Yes

    Yes, class can exists without namespace

    Yes of-course. Namespaces are only meant to avoid the conflict of duplicate class names.

    Yes Class can exist without namespace, It will be in the global namespace and can be referenced like this:var cls = new global::test();

    Its actually possible to create a class without any namespace in .net. However, it takes the global namespace.

    Its actually possible to create a class without any namespace in .net. However, it takes the global namespace.

    Its actually possible to create a class without any namespace in .net. However, it takes the global namespace.

    no

    yes

    yes

    yes

    Yes Using Global Namespace a class can exist without namespace

    Yes I tried. Application working fine . I can access that class. I guess it class should take global namespace

    Its actually possible to create a class without any namespace in .net. However, it takes the global namespace, which is the project name unless it has been explicitly changed the default namespace while creating or after creation of any .net projecthttps://msdn.microsoft.com/en-us/library/c3ay4x3d(VS.80).aspx

    Yes, class can exist without namespace. We can declare multiple inter-related classes under one namespace and can access those classes by using that namespace. Otherwise its not mandatory to declare a namespace but its a good practice.

    Yes.

    Never because namespace is collection of classes , so we cannt imagine the clase without namespace

    Yes, class can exists without name space example: using System; using System.Collections.Generic; using System.Linq; using System.Text;class Program{static void Main(string[] args){Console.WriteLine("hello world");}}Output: hello world

    yes

    Yes, you can create the classes without name space. The name space is used the classes that can have the same name to differ.

    yes. But me need to specify the path of each key word when it is using. By using name space we can reduce the length of our code.

    Yes class can exists without namespace. public class WithoutNameSpace { public void display() { System.Console.WriteLine("WithoutNameSpace"); } } -- class Program { static void Main(string[] args) { WithoutNameSpace ob = new WithoutNameSpace(); ob.display(); } }

    No

    To make the .Net Framework more maintainable Microsoft has given it a hierarchical structure. This hierarchical structure is organized into container called Namespace. Like all .Net Framework classes organized into "System" namespace. So its necessary that a class exist inside a namespace.