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.
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.
private
protected
means they will be accessible to this class or to the derived classes.
In the Namespace level there is no class to derived from so it useless.
You can use only public
or internal
in the Namespace
level
MSDN docs
(I believe you'll actually get a compile-time error; if you're only seeing this at execution time, then chances are your code is being compiled at execution time too, e.g. as part of a web app. Logically it's a compile-time error, not an exception.)
The protected
access modifier (loosely) makes a member accessible to a derived containing type; but in the case of a namespace member there is no containing type.
Likewise a private member's accessibility domain is the program text of the containing type - and again, there is no containing type.
What are you actually trying to achieve by making GetDataBL
protected?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With