C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
.NET
ADO.NET
Android
ASP.NET
C#
Databases & DBA
Design Patterns & Practices
iOS
Java
OOP/OOD
SharePoint
Software Testing
Web Development
WPF
View All
36
Reply
Can class exists without namespace
MD SHAMSE ALAM
10y
4.3k
0
Reply
Delete Row
Delete Column
Insert Link
×
Insert
Cancel
Embed YouTube Video
×
Width (%)
Height (%)
Insert
Cancel
Table Options
×
Rows
Columns
First row as header
Create Table
Insert Image
×
Selected file:
Alignment
Left
Center
Right
Select an image from your device to upload
Upload to Server
Cancel
Submit
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 )
Pankaj Kumar Choudhary
10y
2
Its actually possible to create a class without any namespace in .net. However, it takes the global namespace.
Raghvandra Shukla
9y
1
Yes we can create class without namespace.
Ashish Srivastava
10y
1
yes.
Sridhar Sharma
10y
1
yes we can create
Akash Varshney
10y
1
I myself never have seen any classes without namespace, please explain if you have seen class without namespace.
Joe Wilson
10y
1
No, Without Namespace class can never exists.
Sudheshwer Rai
10y
1
Yes
Mukesh Kumar
8y
0
Yes
Mukesh Kumar
8y
0
Yes
Mukesh Kumar
8y
0
Yes
Mukesh Kumar
8y
0
Yes
Mukesh Kumar
8y
0
Yes
Mukesh Kumar
8y
0
Yes, class can exists without namespace
Ayappan Alagesan
8y
0
Yes of-course. Namespaces are only meant to avoid the conflict of duplicate class names.
Vineet Kumar
8y
0
Yes Class can exist without namespace, It will be in the global namespace and can be referenced like this:var cls = new global::test();
Avikshith Aradhya
9y
0
Its actually possible to create a class without any namespace in .net. However, it takes the global namespace.
Raghvandra Shukla
9y
0
Its actually possible to create a class without any namespace in .net. However, it takes the global namespace.
Raghvandra Shukla
9y
0
Its actually possible to create a class without any namespace in .net. However, it takes the global namespace.
Raghvandra Shukla
9y
0
no
lokesh kumar
10y
0
yes
Pramod Gupta
10y
0
yes
Pramod Gupta
10y
0
yes
Ajeet Mishra
10y
0
Yes Using Global Namespace a class can exist without namespace
Pankaj Kumar Choudhary
10y
0
Yes I tried. Application working fine . I can access that class. I guess it class should take global namespace
Ajay Gandhi
10y
0
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
Shakti Saxena
10y
0
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.
Sanjukta Pearl
10y
0
Yes.
Sachin Kumar
10y
0
Never because namespace is collection of classes , so we cannt imagine the clase without namespace
Vivek Kumar Vishwas
10y
0
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
Vvs Murthy
10y
0
yes
Srikanth Reddy
10y
0
Yes, you can create the classes without name space. The name space is used the classes that can have the same name to differ.
Frank Núñez Rodríguez
10y
0
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.
Alex Varghese
10y
0
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(); } }
Abrar Ahmad Ansari
10y
0
No
Munesh Sharma
10y
0
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.
Sujeet Suman
10y
0
Message