Protected item visible to the user

This will be my first question, so please be lenient.

How is this possible:

//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 (...)";
    }
}

Why am I accessing a protected member since Form1 does not inherit from SomeTableTableAdapter?

+2
source share
2 answers

A property is Adapterdeclared as protected internal, which means that it is available for derived classes ( protected) and for classes in the same assembly ( internal). Because they Form1are in the same assembly as SomeTableTableAdapterthey can access each other's internal members.

+2
source

protected internal . , .

( #):


, , . , , , .

+4

All Articles