Search code examples
c#access-modifiers

Why elements defined in a namespace cannot be explicitly declared?


I have the following C# code:

namespace ISeeOptic.BL
{

  public abstract class Process
  {        
     ...      

     protected static void DeleteImages(List<ImagesPath> list)
      {
          some logic
      } 

      ...
   }


    protected class GetDataBL: Process
    {
      ...

     public static void DeleteImages(List<ImagesPath> list)
     {
         DeleteImages(list); 
     } 
     ...
 }
} 

At compile-time I get the following Error:

Elements defined in a namespace cannot be explicitly declared as private, protected, or protected internal

I'm beginner in C# so maybe this question may seem naive, any idea what cause to this error?

Thank you advance.


Solution

  • Elements defined in a namespace may be explicitly declared public or internal.

    They may not be explicitly declared private or protected (or protected internal) because these modifiers only make sense for members of a class.

    Your protected class GetDataBL, for example, makes no sense, because "protected" means "accessible to classes that inherit from the containing class" -- but there is no containing class for GetDataBL.