C# 框架类中文档化的受保护属性有什么用途?

C# 框架类中文档化的受保护属性有什么用途?,c#,C#,DataGridViewRowCollection具有以下属性: Count (public) Gets the number of rows in the collection. DataGridView (protected) Gets the DataGridView that owns the collection. Item (public) Gets the DataGridViewRow at the specified index. List (protected) Get

DataGridViewRowCollection具有以下属性:

Count (public)
Gets the number of rows in the collection.

DataGridView (protected)
Gets the DataGridView that owns the collection.

Item (public)
Gets the DataGridViewRow at the specified index.

List (protected)
Gets an array of DataGridViewRow objects.
我突然想到一个问题:我将如何使用这些受保护的成员?我假设它们占用文档中的空间是有原因的

我所能想到的、我认为可能有用的场景是派生我自己的类并告诉DataGridView使用该类


但是,我不知道如何做到这一点(也许这很明显,我只是看不到——这就是答案)。

受保护的项目只能从更派生的类访问。这意味着,如果创建一个继承自
DataGridViewRowCollection
MyDataGridViewRowCollection
,则可以访问
DataGridView
列表
属性

要创建从DataGridViewRowCollection继承的类,只需执行以下操作:

public class MyDataGridViewRowCollection : DataGridViewRowCollection
{
    public void MyMethod ()
    {
    }
}

如果不查看所引用的受保护属性的内部工作方式,您的假设是正确的:您可以从DataGridViewRowCollection派生来实现自己的一些专门功能


我假设您还必须将DataGridView重写为实例并使用DataGridViewRowCollection…

DataGridViewRowCollection
未密封,因此您可以从中继承。在这种情况下,您可以调用这些方法,因此它们有文档