There are two reasons that I would (and do) use partial classes.
- To separate auto-generated portions of the code (such as WinForms designer code or T4 output).
- To allow nested types their own file while still achieving the encapsulation required by your design.
Update
I can see that some are not convinced about my second point, so let me give an example; the ListViewItemCollection
in the framework. It is quite rightly nested under ListView
because it is only for use by ListView
, but to make maintenance much easier, I would give it it's own file by using partial classes. I don't see this as bad design or a misuse of the partial
keyword.
For more discussion, check out the question that this one duplicates: Partial Classes in C#