Question Partial vs Abstract classes?


New member
Mar 7, 2014
Programming Experience
Hi programming fanatics i am unable to endvour what partial classes are created for and how do they differ from Abstract classes. please help....:emptiness:....:confusion:
You should certainly follow the links provided by JohnH but I'll provide my own brief explanation. Firstly, partial an abstract classes are completely unrelated so don't even try to compare them. They have nothing specifically to do with each other except that they both relate to classes.

Abstract classes are intended to be used as a base for other classes. Some properties and/or methods will generally be declared in an abstract class with some of them having an implementation but perhaps some of them not. Any members declared abstract must be overridden in a derived class. An example of an abstract class is CollectionBase. As the name suggests, that class is intended to be a base class for collections. You cannot create an instance of the CollectionBase class but you can declare your own class that inherits CollectionBase and inherit that.

A partial class is where one part of a class is declared in one code file and one or more other parts may be declared in other code files. The most obvious example of partial classes is the Windows Forms designer. When you create a Windows Forms application, two code files are created for each form. The default form will be named Form1 and you will see both Form1.cs and Form1.designer.cs in the Solution Explorer. The designer file contains the designer-generated code and the other contains your user code. The idea is that you can muck around with your code as much as you like without accidentally breaking the designer code and also your code won't be erased by regeneration of the designer code. Partial classes are often used in that way, i.e. to separate generated code from user code, e.g. adding validation attributes to EF entity classes. When you build your project, the compiler treats each of the partial classes as part of the same class, so they are compiled as though they were just one code file.
Top Bottom