C# – DataRow and the protected internal constructor

.netc++constructordatarowdatatable

How can a DataTable create a new instance of a DataRow with the NewRow method if the constructor of the DataRow class is protected internal and DataTable doesn't inherit from DataRow?

Example:

class Program
{
    static void Main()
    {
        // error: inaccessible due to its protection level
        DataRow dr = new DataRow(); 

        // works
        DataRow dr = new DataTable().NewRow();
    }
}

Best Solution

protected internal means "accessible by derived classes" and "accessible by other classes in the same assembly". DataTable and DataRow are in the same assembly, so DataTable has access to all of DataRow's internal members.