What is the use of a partial class?

前端 未结 10 884
梦谈多话
梦谈多话 2021-01-13 00:15

How can a partial class be useful in coding? Can anyone explain in detail with examples?

相关标签:
10条回答
  • 2021-01-13 00:53

    Partial class is use full when multiple users are working on same class so keyword partial is used. but when compiler compiles the code it combine all partial classes with same name to one class.hence it reacts as one class.

    0 讨论(0)
  • 2021-01-13 00:56

    This might help you out.

    http://www.4guysfromrolla.com/articles/071509-1.aspx

    0 讨论(0)
  • 2021-01-13 01:01

    Another use: if you have a giant tab control with many tabs that you want to split into one tab's code per file, you can do that with partials.

    0 讨论(0)
  • 2021-01-13 01:05

    The most prevalent example is in code-generation. The WinForms designer as of Visual Studio 2005 does this. It allows code-generated code to go into one file, while your hand-crafted code stays in another file. They are glued together at the end by the compiler.

    0 讨论(0)
  • 2021-01-13 01:13
    1. When working on large projects, spreading a class over separate files allows multiple programmers to work on it simultaneously.
    2. 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.

    Source msdn.

    Have a look at this link.

    0 讨论(0)
  • 2021-01-13 01:13

    I have seen people using partial classes to separate classes that are too large into separate files - where a better solution would be to split the class up into many separate classes.

    I consider it an anti-pattern to use partial classes for splitting hand written classes into separate files.

    0 讨论(0)
提交回复
热议问题