Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C#: why can I not create a system namespace?

Tags:

c#

I remember few weeks ago when I reorgnized our code and created some namespaces in our project I got error and the system did not allow me to create a companyName.projectName.System namespace, I had to change it to companyName.projectName.Systeminfo. I don't know why. I know there is a System namespace but it is not companyName.projectName.System. I think A.B.C namespace should be different with A.A.C namespace. Right?

EDIT

The error I got is like the this:

Error   7   The type or namespace name 'Windows' does not exist in the namespace 'MyCompany.SystemSoftware.System' (are you missing an assembly reference?) C:\workspace\SystemSoftware\SystemSoftware\obj\Release\src\startup\App.g.cs 39  39  SystemSoftware
like image 787
5YrsLaterDBA Avatar asked Mar 10 '10 19:03

5YrsLaterDBA


People also ask

What C is 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 ...

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

What is C full form?

History: The name C is derived from an earlier programming language called BCPL (Basic Combined Programming Language). BCPL had another language based on it called B: the first letter in BCPL.


2 Answers

You're experiencing a namespace clash.

If you name the last part of your namespace System, then the compiler will have a hard time determining if you're referring to the (Microsoft) System namespace or an inner System namespace at your current level (or even an System class or property or ...).

You'll experience the same problem with class names and namespace parts. You can't create a class called System for the same reasons.

Unless you feel like specifying full namespaces for all of your instances.

like image 127
Zyphrax Avatar answered Sep 22 '22 22:09

Zyphrax


The code below compiles and runs, so I think you'll need to give us a bit more detail as there's no reason you can't create a namespace such as companyName.projectName.System as far as I'm aware.

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = new ConsoleApplication1.Project.System.Something();
        }
    }
}
namespace ConsoleApplication1.Project.System
{
    public class Something
    {
    }
}
like image 32
Rob Avatar answered Sep 23 '22 22:09

Rob