Conflicting Modifiers for Partial Class?

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
 
B

Brant Estes

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top