I am deriving a class from String
, but it won't allow me to inherit from that class. What do I need to do if I want to inherit like this?
public class a : string
{
//class definition
}
I am deriving a class from String
, but it won't allow me to inherit from that class. What do I need to do if I want to inherit like this?
public class a : string
{
//class definition
}
You cannot inherit from String
because it is sealed. If you have to extend the provided functionality, you have two options:
String
and implement the methods yourself.You cannot inherit from string
class as it is sealed
.
For any additional behavior to the string
class consider creating extension methods.
Short answer :
You can't derive from basic type.
Long answer :
You can't because the String
class is maked as sealed, preventing inheritance.
If you want to add methods to the string object, you can use extention methods (more info here : https://msdn.microsoft.com/en-us/library/bb383977.aspx)