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?
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.