Geeks With Blogs

AzamSharp Some day I will know everything. I hope that day never comes.

Partial Classes means that your class defination might be in multiple files. This way you can organize your files more efficiently. Look at the example below I have the class "Customers " but its defined in multiple files:

Customer.cs:

This simply contains a single constructor and thats it!

public partial class Customer
{
    
public Customer()
    {
        
    }
}

Customer.Methods.cs:

This can contain the methods of the Customer Class.

partial class Customer
{
    
public void GetCustomers()
    {
        
// Code for getting all the customers 
    
}

    
public void GetCustomerByID(int customerID)
    {
        
// Code to get a customer by ID 
    
}    
}

Customer.Properties.cs:

This can contain the properties of the Customer Class.

partial class Customer
{
    
private readonly int _customerID;
    
private string _customerName;

    
public int CustomerID
    {
        
get return _customerID; } 
    }

    
public string CustomerName
    {
        
get return _customerName; }
        
set { _customerName = value; } 
    }

}

Hence, you see that now the Customer Class is more organized. This is ideal for team work when multiple users can work on the same class without having a local copy of the same class.

powered by IMHO

 

Posted on Wednesday, November 23, 2005 3:16 PM | Back to top


Comments on this post: Partial Classes in 2.0

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net