locked
Partial Classes RRS feed

  • Question

  •  

    In my never ending search for more knowledge, I have come across Partial Classes.  I was wondering if some of the kind people who actually understand the uses could explain some of them to me.  Now I know that when we create a form that we actually create a partial class which the generator rewrites when we add a control or change a property at design-time, and this allows us not to have to worry about setting up the controls ourselves.

     

    But what are the uses in hand-coded classes, what are the adavatages of using partial classes insted of just putting all of the code into a full class.  I have looked through some of the posts here but most of them just hint at applications so I thought I would ask.

    Wednesday, March 26, 2008 12:50 PM

Answers

  • I don't think that there is anything special about Partial Classes.  Instead I regard them more as a variation of the Include files that I used to use when I programmed in Pascal.  (I believe C and C++ use Include files as well).  Where code logically belongs in a single class, but the class is getting rather large, it can be convenient to break it up into smaller logical units - without having to perhaps artifically create a new class for some part of the code.  You could perhaps look at them as an altenative to and an extension to the Regions that VB.Net introduced us to.

     

    Hope this helps.

    Wednesday, March 26, 2008 2:05 PM

All replies

  • I don't think that there is anything special about Partial Classes.  Instead I regard them more as a variation of the Include files that I used to use when I programmed in Pascal.  (I believe C and C++ use Include files as well).  Where code logically belongs in a single class, but the class is getting rather large, it can be convenient to break it up into smaller logical units - without having to perhaps artifically create a new class for some part of the code.  You could perhaps look at them as an altenative to and an extension to the Regions that VB.Net introduced us to.

     

    Hope this helps.

    Wednesday, March 26, 2008 2:05 PM
  • In those rare cases where we have had two people working on the same class, we occasionally use partial classes so that the two people can work on their code independently. Works fairly well for that purpose.
    Monday, April 23, 2012 5:27 PM