The partial keyword is not limited to just classes. It may
also be used for interfaces and structs. When you're creating an interface or a
struct you might also want to have the code separated. You declare a partial
interface or a partial struct the same way as the partial class. You simply add
in the keyword partial. The following code shows how to declare a simple
partial interface and a simple partial struct.
Listing 4: Simple Partial Interface
public partial interface IPlayable
{
Move GetMove();
}
This is just one partial interface defined here. We might
have another piece located elsewhere. This is a very simple interface and it is
obviously for my AIPlayer I listed above.
Listing 5: Simple Partial Struct
public partial struct Move
{
public int column, row;
public Move(int c, int r)
{
column = c;
row = r;
}
}
We use these the same way we use partial classes, and for
the same reasons. Make sure that you're always using the partial keyword for
every definition of the class, interface, or struct. You will probably less
often need to use interfaces and structs as partial, but if the need arises now
you know. You'll be able to create these as partial and allow for more
maintainability in your code.