Can you make a partial
class file for a class that is sealed
?
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.
Sealed classes and interfaces represent restricted class hierarchies that provide more control over inheritance. All direct subclasses of a sealed class are known at compile time. No other subclasses may appear outside a module within which the sealed class is defined.
A partial class is a special feature of C#. It provides a special ability to implement the functionality of a single class into multiple files and all these files are combined into a single class file when the application is compiled. A partial class is created by using a partial keyword.
A Sealed class cannot be inherited from and can static and non-static members or methods. Contains a public constructor. 2. A Static class cannot be inherited from and contains only static methods and class properties.
The sealed
keyword simply means that the class cannot be inherited. It has no impact on how the class' code is structured otherwise. The partial
keyword simply allows a class to be split among several files.
In the sample below, class A compiles just fine. B does not compile because A is sealed and inheritance is not allowed.
public sealed partial class A { private int x; }
public sealed partial class A { private int y; }
public class B : A { }
It seemed to compile fine.
sealed partial class Class1
{
public void MyMethod() { }
}
partial class Class1
{
public void MyMethod2() { }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With