Is it possible to extend primitive types such as System.String and System.Int32 (IE: integer) in .Net 4 and if so how?
To be more specific, I am aware of the concept of partial classes but this doesnt seem to be the answer. Also I find that System.String is not inheritable and Int32 is a structure.
Lastly I am interested in knowing both a VB.Net and C# answer to the above question.
Thanks all..
You cannot extend them directly – the
Stringclass is sealed, for example, and as you noted value type wrappers (such asInt32) are normally structs.You can write extension methods (C#, VB.NET) to them, that’s what they are there for.
Another option, is to write a wrapper around these, exposing all of their properties and adding more functionality.