MD SHAMSE ALAM
Can class exists without namespace
By MD SHAMSE ALAM in C# on Jun 16 2015
  • Pankaj  Kumar Choudhary
    Jul, 2015 2

    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 )

    • 2
  • Raghvandra Shukla
    Mar, 2016 27

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

    • 1
  • Ashish Srivastava
    Dec, 2015 20

    Yes we can create class without namespace.

    • 1
  • Sridhar Sharma
    Nov, 2015 13

    yes.

    • 1
  • Akash Varshney
    Oct, 2015 10

    yes we can create

    • 1
  • Joe Wilson
    Jul, 2015 20

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

    • 1
  • Sudheshwer  Rai
    Jun, 2015 26

    No, Without Namespace class can never exists.

    • 1
  • Mukesh Kumar
    Sep, 2017 12

    Yes

    • 0
  • Ayappan Alagesan
    Feb, 2017 12

    Yes, class can exists without namespace

    • 0
  • Vineet Kumar
    Jan, 2017 13

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

    • 0
  • Avikshith Aradhya
    Jun, 2016 3

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

    • 0
  • Raghvandra Shukla
    Mar, 2016 27

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

    • 0
  • Raghvandra Shukla
    Mar, 2016 27

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

    • 0
  • Raghvandra Shukla
    Mar, 2016 27

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

    • 0
  • lokesh kumar
    Dec, 2015 18

    no

    • 0
  • Pramod Gupta
    Sep, 2015 23

    yes

    • 0
  • Pramod Gupta
    Sep, 2015 23

    yes

    • 0
  • Ajeet Mishra
    Sep, 2015 3

    yes

    • 0
  • Pankaj  Kumar Choudhary
    Aug, 2015 31

    Yes Using Global Namespace a class can exist without namespace

    • 0
  • Ajay Gandhi
    Aug, 2015 25

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

    • 0
  • Shakti Saxena
    Aug, 2015 18

    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

    • 0
  • Sanjukta Pearl
    Aug, 2015 18

    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.

    • 0
  • Sachin Kumar
    Jul, 2015 25

    Yes.

    • 0
  • Vivek Kumar Vishwas
    Jul, 2015 22

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

    • 0
  • Vvs Murthy
    Jul, 2015 16

    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

    • 0
  • Sreekanth Reddy
    Jul, 2015 11

    yes

    • 0
  • Frank Núñez Rodríguez
    Jul, 2015 9

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

    • 0
  • Alex Varghese
    Jul, 2015 6

    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.

    • 0
  • Abrar Ahmad Ansari
    Jul, 2015 1

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

    • 0
  • Munesh Sharma
    Jun, 2015 28

    No

    • 0
  • Sujeet Suman
    Jun, 2015 26

    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.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS