Public class is inaccessible due to its protection level

后端 未结 3 1268
情歌与酒
情歌与酒 2020-12-29 18:45

I have the following classes:

namespace Bla.Bla 
{
    public abstract class ClassA 
    {
        public virtual void Setup(string thing) 
        {
                


        
相关标签:
3条回答
  • 2020-12-29 18:57

    You could go into the designer of the web form and change the "webcontrols" to be "public" instead of "protected" but I'm not sure how safe that is. I prefer to make hidden inputs and have some jQuery set the values into those hidden inputs, then create public properties in the web form's class (code behind), and access the values that way.

    0 讨论(0)
  • 2020-12-29 19:01

    Also if you want to do something like ClassB.Run("thing");, make sure the Method Run(); is static or you could call it like this: thing.Run("thing");.

    0 讨论(0)
  • 2020-12-29 19:05

    This error is a result of the protection level of ClassB's constructor, not ClassB itself. Since the name of the constructor is the same as the name of the class* , the error may be interpreted incorrectly. Since you did not specify the protection level of your constructor, it is assumed to be internal by default. Declaring the constructor public will fix this problem:

    public ClassB() { } 
    

    * One could also say that constructors have no name, only a type; this does not change the essence of the problem.

    0 讨论(0)
提交回复
热议问题