Reputation: 9489
In C#, what is the significance of a sealed partial class?
A Sealed class is a class that cannot be inherited.
A partial class is a class that can be split between 2 or more source files.
So why does a "sealed partial class have any significance?
Upvotes: 4
Views: 10590
Reputation: 876
There is no relationship of the two keywords.
It is just a class doesn't want to be inherited happens to be split.
You can have only seal or only split or both. It only depends on how you want the behavior to be.
Upvotes: 0
Reputation: 7026
Sealed partial class can be used mainly in classes with lot of LOC, which should not be inherited.
Sealed partial together doesn't mean something significant and as you have already mentioned both are used for different purposes.
Upvotes: 0
Reputation: 56
Partial class allows us to write a class across multiple files in a project. Partial indicates that the parts of the class can be defined in the namespace and all the parts must be used with the partial keyword. if any part is declared as sealed then the whole type is considered sealed.
Upvotes: 3
Reputation: 1708
A partial class is basically just syntactic sugar, you can define a class in two different files, in the same assembly. This is useful when part of your class is generated, for example using the Entity Framework DB first approach. It has nothing to do with inheritance.
A sealed class is a class that cannot be inherited. You would make a class sealed if inheriting from it could potentially break it, but you need it to be accessable outside of your own code.
There is no relation between the two keywords. A sealed partial class is simply a class, that might be defined in more files, and cannot be inherited from.
Upvotes: 14