Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the partial mean?

public partial class Form1 : Form

What does the partial in this declaration mean? I understand we have a class Form1 that inherits from Form. But what does the partial mean?

like image 650
RoR Avatar asked Oct 05 '10 06:10

RoR


People also ask

What is the meaning of partial payment?

What Does Partial Payment Mean? Partial payment means a payment that is less than the full amount due. Other terms for partial payment include part payment, installment payment, down payment, or upfront payment.

What do we mean by partial?

Definition of partial (Entry 1 of 2) 1 : of or relating to a part rather than the whole : not general or total a partial solution a partial payment. 2 : inclined to favor one party more than the other : biased it is inconsistent with justice to be partial— J. S. Mill.


2 Answers

It allows you to split the definition of your class into two or more separate files.

See this MSDN article, "Partial Class Definitions" for more information:

It is possible to split the definition of a class or a struct, or an interface over two or more source files. Each source file contains a section of the class definition, and all parts are combined when the application is compiled. There are several situations when splitting a class definition is desirable:

  • When working on large projects, spreading a class over separate files allows multiple programmers to work on it simultaneously.
  • When working with automatically generated source, code can be added to the class without having to recreate the source file. Visual Studio uses this approach when creating Windows Forms, Web Service wrapper code, and so on. You can create code that uses these classes without having to edit the file created by Visual Studio.

You're likely referring to the default behavior of Visual Studio when creating forms. This allows the definition of the form to be split between the file that you own and can modify, and the file that Visual Studio owns (Form1.Designer.cs). This avoids a lot of headaches we saw with Visual Studio 2002 and 2003, when the developer and the IDE would step over each other's toes all the time with their edits.

like image 134
Michael Petrotta Avatar answered Oct 27 '22 03:10

Michael Petrotta


This permits partial class definitions in source files which are combined into a single class at compilation. In your case one half of the class code is autogenerated by the code generator and hidden from you in a file with partial class declaration (there will be a lot of code in there). You are given a clean slate with partial class definition to allow you to enter code in this partial definition so at compilation the autogenerated code and your code are combined into a single class derived from the class Form. Its a commone way of of combining the machine's and the man's code in visual designers etc to allow you to not write the plumbing boring code and just concentrate on what you will like to do.

like image 37
explorer Avatar answered Oct 27 '22 02:10

explorer