Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 受保护的成员对用户可见_C#_.net_Winforms_Protected_Access Modifiers - Fatal编程技术网

C# 受保护的成员对用户可见

C# 受保护的成员对用户可见,c#,.net,winforms,protected,access-modifiers,C#,.net,Winforms,Protected,Access Modifiers,这将是我在这里的第一个问题,所以请宽容 这怎么可能: //there is a Form1 class which has a TableAdapter member generated by designer... partial class Form1 { private void InitializeComponent() { this.SomeTableTableAdapter = new SomeDatabaseDataSetTableAdapters

这将是我在这里的第一个问题,所以请宽容

这怎么可能:

//there is a Form1 class which has a TableAdapter member generated by designer...
partial class Form1
{
    private void InitializeComponent()
    {
         this.SomeTableTableAdapter = new SomeDatabaseDataSetTableAdapters.SomeTableTableAdapter();
    }

    private SomeDatabaseDataSetTableAdapters.SomeTableTableAdapter SomeTableTableAdapter;
 }

//here is this TableAdapter class
//It has PROTECTED member called "Adapter"
public partial class SomeTableTableAdapter : global::System.ComponentModel.Component
{
    protected internal global::System.Data.SqlClient.SqlDataAdapter Adapter
    {
    }
}

//and in the constructor of Form1 class I can do something like this:
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        this.SomeTableTableAdapter.Adapter.InsertCommand.CommandText = @"INSERT INTO (...)";
    }
}

既然Form1不从SomeTableAdapter继承,我怎么能访问受保护的成员?

适配器
属性声明为
受保护的内部
,这意味着它可以被派生类(
受保护的
访问,也可以被同一程序集中的类(
内部
)访问。由于
Form1
SomeTableAdapter
位于同一程序集中,因此它们可以访问彼此的内部成员。

受保护的内部
表示受保护或内部。允许从派生类或包含程序集进行访问

:

受保护的内部
类型或成员可以由声明它的程序集中的任何代码访问,也可以从另一个程序集中的派生类中访问。来自其他程序集的访问必须在从声明受保护内部元素的类派生的类声明中进行,并且必须通过派生类类型的实例进行


请使用网站功能回复答案,如留言。由于这是一个问答网站,答案实际上不是答案。别忘了将答案标记为已接受。