C # .NET The namespace name does not exist in the namespace error - only when used outside the local namespace directive - why?

Using .NET 2.0, C #, development of Windows Forms, Enterprise Library 3.1.

We have a project namespace (name it Project). We also have several subspaces inside this project, for example Project.Namespace1, Project.Namespace2, etc.

In one class, we define enumerations and those that will be used with the corporate library journal block, for example:

namespace Project.Logging
{
  public static class Logging
  {
    public enum LogPriority
    {
      // enum values here
    }
  }
}

In another class, I use enumeration values, so I need to declare a using statement. The same project, so there is no link to the link, right?

If I declare use inside a local namespace like this, it works fine:

namespace Project.SomeName
{
  using Project.Logging;

  // code referencing the Logging enum
}

, using , " " LogPriority "Project.Logging"... :

using Project.Logging;

namespace Project.SomeName
{
  // code referencing the Logging.LogPriority.whatever
}

? - ?

+3
5

( ) , , .

, , , . , .

namespace Project.Logging
{  
  public static class Logging  // this is what caused the probems for me
  {   

  }
}
+2

. - , , . , , .NET framework.

+2

, , , " " . .

+1

, .

Services.Web.xxx, Services.Web.xxxx Services.Web.xxx, , .

, , , , Services

You can also do the following and create an alias for LogPriority for LogEnum:

using LogEnum= Project.Logging.Logging.LogPriority;

namespace Project.SomeName
{
    internal class MyClass
    {
        public MyClass()
        {
            LogEnum enum1 = LogEnum.None;
        }
    }
}
namespace Project.Logging
{
    public static class Logging
    {
        public enum LogPriority
        {
            None,
            Default
        }
    }
}
0
source

This can definitely make a difference if you have applications inside or outside the namespace. There is a good discussion here , and it will probably be related to your default namespace settings.

-1
source

Source: https://habr.com/ru/post/1723382/


All Articles