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
{
}
}
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; }
}
}
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!