错误1'classlibrary3.trunk.trunk()'由于其保护级别而无法访问

问题描述:

namespace ClassLibrary3
{
     class SIPtrunk : Trunk
    {

        private int IPSigRemote; // Destination Point Code

        private int Capacity; // Nombre de circuits * 32

        private string GroupDirection; // IN, OUT, Bi-Directionnel



       void GetSIPtrunk()
        {



        }
       void GetSIPtrunk(int ips, int capacity, string groupdirection)
        {
            this.Capacity = capacity;
            this.GroupDirection = groupdirection;
            this.IPSigRemote = ips;

        }



    }
}





我尝试过:



命名空间ClassLibrary3

{

class SIPtrunk:Trunk //问题在这里

{



private int IPSigRemote; //目的地点代码



private int容量; // Nombre de circuits * 32



private string GroupDirection; // IN,OUT,Bi-Directionnel







void GetSIPtrunk()

$







}

void GetSIPtrunk(int ips ,int capacity,string groupdirection)

{

this.Capacity = capacity;

this.GroupDirection = groupdirection;

this.IPSigRemote = ips;



}







}

}



What I have tried:

namespace ClassLibrary3
{
class SIPtrunk : Trunk// the problem is here
{

private int IPSigRemote; // Destination Point Code

private int Capacity; // Nombre de circuits * 32

private string GroupDirection; // IN, OUT, Bi-Directionnel



void GetSIPtrunk()
{



}
void GetSIPtrunk(int ips, int capacity, string groupdirection)
{
this.Capacity = capacity;
this.GroupDirection = groupdirection;
this.IPSigRemote = ips;

}



}
}

正如我之前提到的那样:

As I said when you asked this earlier:
Quote:

想一想:如果B类派生自A类,那么B类包含A类的所有属性,方法和字段以及它自己添加的任何内容。



因此,要在您的应用中使用B类,您的代码必须能够访问所有A类功能,无论它在何处应用程序。



现在假设你有两个Assemblies,一个包含A和B类,另一个只尝试使用B类。如果无法从第二个程序集访问A类,因为它被标记为protected,internal,甚至是private,但是B被声明为public,那么您编写的使用它的代码根本无法访问A类 - 所以它不会知道B级真正包含和能够做什么 - 结果你得到不一致的可访问性错误。



要么改变A类的访问权限,要么为B类,或者将类A实例封装在B中,而不是从它派生。

Think about it: if class B is derived from class A then class B contains all the properties, methods, and fields of class A as well as any it adds itself.

So to use class B in your app, your code must be able to access all class A features regardless of where it is in the app.

Now suppose you have two Assemblies, one containing classes A and B, and the other trying to use class B only. If class A is not accessible from the second assembly because it is marked as protected, internal, or even private but B is declared as public, the code you write to use it can't access class A at all - so it doesn't know what class B is truly containing and capable of - and you get an "inconsistent accessibility" error as a result.

Either change the access for class A, or for class B, or encapsulate the class A instance in B instead of deriving from it.

除非Trunk也是 public ,否则这将不起作用。

Unless Trunk is also public this will not work.