Creating a partial class in C #

I am a student and I do not know what a partial class . The following code is for a partial class

I automatically created a partial class:

 public partial class EGUI: Form { private OleDbConnection dbConn; // Connectionn object private OleDbCommand dbCmd; // Command object private OleDbDataReader dbReader; // Data Reader object private Emp Edetails; private string sConnection; private string sql; } 
+6
c #
source share
4 answers

First of all, THIS: http://msdn.microsoft.com/en-us/library/wa80x488(v=vs.80).aspx

Secondly, it allows the programmer to collect certain pieces of code into two different files. A good example of this is the creation of ASP.NET WebForm. WebForm will have a file for your event handlers and such (Button_Click, etc.), and then you will have an additional file containing declarations of ASP.NET controls that you use on your page. This saves the code that you invert in one file, and the more obvious “automatically generated” material in another.

Correct me if I am wrong, but I also believe that partial classes can allow you to do something like "monkey switching", because it provides the class so that you can add new methods, variables, etc. and have access to private member classes.

+2
source share

Here is the final answer: http://msdn.microsoft.com/en-us/library/wa80x488(v=vs.80).aspx

You can break up a class or structure definition, or an interface through two or more source files. Each source file contains a class definition section and all parts are combined when the application is compiled.

+5
source share

A partial class is a class whose definition can be shared between different files within the same project / assembly. For example, Visual Studio Forms Designer makes extensive use of this functionality to separate the design-time elements that you placed on the form from the actual code, and once the project is compiled, the two source files are combined to emit the resulting class.

+2
source share

Check this. For starters, there is a simple example for partial classes and partial methods.

http://w3mentor.com/learn/asp-dot-net-c-sharp/object-oriented-concepts-c-sharp/partial-class-and-partial-method-in-c/

+1
source share

All Articles