C# Error - Elements defined in a namespace cannot be explicitly declared as private, protected, or protected internal

0
=
0
+
0
No specific Bitcoin Bounty has been announced by author. Still, anyone could send Bitcoin Tips to those who provide a good answer.
0

Getting the following compile error:

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

Here is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace MyProject.Controllers
{
    protected class MyControllerBase : ApiController
    {

    }
}
Tags:

1 Answer

1
=
0
=
$0
Internet users could send Bitcoin Tips to you if they like your answer!

n response to your questions:

A class within a namespace (and not within another class) can only be declared as public or internal. HOWEVER, a class within another class can be declared as protected internal, private, etc.

Yes, protected internal can be used inside a class whose access modifier is more strict than it's members, see example of a perfectly valid usage below (note that the class is inside the Program class):

public class Program
{
    static void Main(string[] args)
    {
    }

    private class Foo
    {
        private int priv { get; set; }
        protected internal int protint { get; set; }
        public int pub { get; set; }
    }
}
SEND BITCOIN TIPS
0

Too many commands? Learning new syntax?

FavScripts.com is a free tool to save your favorite scripts and commands, then quickly find and copy-paste your commands with just few clicks.

Boost your productivity with FavScripts.com!

Post Answer