Conflicting Modifiers for Partial Class?

  • Thread starter Thread starter Cody Powell
  • Start date Start date
C

Cody Powell

I have a partial class split across two files. In the class
declaration found in the first file, I state that it's a sealed class.
In the class declaration found in the second file, I do not use the
keyword sealed. This compiles fine. When I actually try to inherit
from this class, I see that it's sealed.

Can someone explain how this works? If a modifier is found in only one
part of a partial class declaration, will the modifier always apply to
every instance of the class? (Note: we'd see a compile error if I
tried to mix two opposed modifiers, like abstract and sealed.) I
didn't expect my original experiment to work, and then it did; it's
both neat and a little confusing. Any clarification is appreciated.
Thanks,

Cody Powell
 
Think of partial classes as single classes which span two or more
files. Omitting parts of the class declarations are fine, as long as
they don't confict, like you've discovered. The two (or more) classes
will effectively be merged together at compile time.
 
Back
Top