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 - total earned - 0 BTC ($0 USD)

1
=
0
=
$0
Everyone, even non-registered users could send Bitcoin Tips to YOU if they are inspired by 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

Post Answer


Will Bitcoin Tipping become a new Internet Culture?


Please share our story! THANK YOU!