May 10, 2005

Partial Classes

How many times we wished if we can work on the same class file while some other developer checkout the same file. Writing two methods by two developers on the same time on the same class file is barely impossible. But now its possible with Partial Classes(new C# Feature). You can split your class file into multiple files. check out the example below.


//partial class 1
public partial class Customer
{
private string _name;
private int _age;
}
//partial class 2
public partial class Customer
{
public string Name
{
get{return _name;}
set{_name = value;}
}
public int Age
{
get{return _age;}
set{_age= value;}
}
public void ShowMyName()
{
return Name;
}
}
public class MyBusiness
{
public void ShowCustomers()
{
Customer customer = new Customer();
customer.ShowMyName();
}
}

1 comment:

Madhawa said...

hay that’s cool bro...
now we can split classes which got too many lines on it..:)
cheers!!!