Popular Posts

Monday, February 21, 2011

Good feature of C#:Partial classes

Partial classes give you the ability to split a class into more than one source code .cs file.
If a class becomes particularly long and intricate you might decide to break it into pieces as shown below


//This file is stored in the Product.cs

public partial class Product
{
private string name;
private decimal price1;
public string Name
{

}

public decimal Price
{

}

public string ImageUrl
{

}

}

public partial class Product
{
//continued code here
}



these two  partial classes comprise one class Product and are divided to simplify coding.

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. hey don't you think that with such kind of programming, the code will actually be scattered and debugging or finding the exact declarations/definitions will get more tedious ??

    ReplyDelete
  3. These two partial classes are stored in two different .cs files ...So it will simplify the coding.
    So the first partial class will be stored for example in Product1.cs and the second partial class will be stored in Product2.cs.

    ReplyDelete