Using Inner classes in C#

前端 未结 9 1911
粉色の甜心
粉色の甜心 2020-12-02 18:40

What are the best practices regarding the use and structure of inner classes in C#.

For instance if I have a very large base class and two large inner classes should

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-02 19:19

    I don't have the book to hand, but the Framework Design Guidelines suggests using public inner classes as long as clients don't have to refer to the class name. private inner classes are fine: nobody's going to notice these.

    Bad: ListView.ListViewItemCollection collection = new ListView.ListViewItemCollection();

    Good: listView.Items.Add(...);

    Regarding your large class: it's generally worthwhile splitting something like this into smaller classes, each with one specific piece of functionality. It's difficult to break it up initially, but I predict it'll make your life easier later on...

提交回复
热议问题