受保护的成员用户可见 [英] Protected member visible for user
本文介绍了受保护的成员用户可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这将是我的第一个问题在这里,所以请手下留情。
It will be my first question here so please be lenient.
这怎么可能:
//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中不会从SomeTableTableAdapter继承?
How come I get access to protected member since Form1 do not inherit from SomeTableTableAdapter?
推荐答案
在适配器
属性被声明为受保护的内部
,这意味着它可以访问派生类(保护
)和以班级在同一组件(内部
)。由于 Form1中
在同一个组件, SomeTableTableAdapter
,他们可以访问对方的内部成员。
The Adapter
property is declared as protected internal
, which means it is accessible to derived classes (protected
) and to classes in the same assembly (internal
). Since Form1
is in the same assembly as SomeTableTableAdapter
, they can access each other's internal members.
这篇关于受保护的成员用户可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文