Net-informations.com
SiteMap  | About    

What is partial class ?

partial class in C# vb.net asp.net

When working on large projects, spreading a class over separate physical files enables multiple developers to work on it at the same time. Partial classes allow for a single Class file to be split up across multiple physical files, and all parts are combined when the application is compiled.

Ex:

Entaire Class definition in one file (billing.cs).

public class Billing { public bool Add() { } public bool Edit() { } }

Same class in the above code split across multiple files.

billing_1.cs

public partial class Billing { public bool Add() { } }

billing_2.cs

public partial class Billing { public bool Edit() { } }

Advantages:

interview question and answers C# vb.net asp.net

The biggest use of partial classes is that using Partial Classes multiple programmers can work on the same class easily. Partial classes are mainly used by code generator because the code can be added to the class without having to recreate the source file. Moreover, it's easier to categorize code with partial classes.

Consider the following points while implementing the partial classes:

The partial keyword indicates that other parts of the class can be defined in the same namespace. All the parts should use the partial keyword. All the parts should be available at compile time to form the final type. All the parts should have the same accessibility, such as public, private, and so on.

object oriented programming C# vb.net asp.net

If you inherit a class or interface on a partial class, then it should be inherited on all parts of a partial class. If a part of the partial class is sealed , then the entire class will be sealed. Also if a part of the partial class is abstract, then the entire class will be an abstract class.







net-informations.com (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.