I am looking to create a custom string.GetHashCode() method for some of the strings used in a program namespace (as recommended on the string.GetHashCode() msdn page here) Unfortunately the string class is inheritance sealed.
The closest I have gotten is a base class with a string-typed Value accessor, but that will be a little annoying in that the code will read:
CustomStringTypeInstnce.Value.GetHashCode();
instead of the nicer:
CustomStringTypeInstnce.GetHashCode();
that would be possible if the string class were not inheritance sealed. Is the code read I am looking for at all possible?
if not,.. I don't necessarily need to or not need to override the base class string.GetHashCode(), for the entire program namespace but that would work too, how would that be done?
(EDIT) Sorry, got a little attention-tracked, yes, could just use
CustomStringTypeInstnce.GetHashCode();
as suggested by AppDeveloper's answer, I was/am also looking to be able to assign a string to the wrapped string variable directly without having to use an accessor, but I guess that pretty much means using the prohibited inheritance.
i dont think, you can!
String class is sealed for a reason to disallow any such modification.
You can do, expose create Class like