Understanding and Using Partial Classes in C#
page 6 of 8
by Brendan Enrick
Feedback
Average Rating: 
Views (Total / Last 10 Days): 10843/ 460

Partial Interfaces and Structs

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.


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 2 and 2 and type the answer here:

User Comments

Title: not decribe well   
Name: vivek rai
Date: 5/4/2008 7:21:53 AM
Comment:
u r not able to decribe well....

Product Spotlight
Product Spotlight 
Learn More
.NET Tools
asp.net shopping cart
asp.net chart control






Ads Powered by Lake Quincy Media
Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2008 ASPAlliance.com  |  Page Processed at 8/29/2008 8:57:15 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search