partial class in c#


what is partial classes in c#

Comments

  • :
    : what is partial classes in c#
    :
    Put simply (and it is really simple ;) it allows code completely defining class members (fields, methods, events and properties) to span multiple files, rendering the programmer in control of code layout.
  • :
    : what is partial classes in c#
    :

    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.

    To split a class definition, use the partial keyword modifier, as shown below:

    public partial class Employee
    {
    public void DoWork()
    {
    }
    }

    public partial class Employee
    {
    public void GoToLunch()
    {
    }
    }


    Brad Wang
    .NET Freelancer from China
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories