Manipulate sealed type in C#

c#, extension-methods, inheritance, oop

Solution

You can add an extension method for `int32`.

   public static class Int32Extensions
   {
       public static void HelloWorld(this int value) 
       {
         // do something
       }
   }

Just remember to `using` the namespace the class is in.

Problem

I want to, for example, add a method to `integer` (i.e., `Int32`), which will make me able to do the following: ``` int myInt = 32; myInt.HelloWorld(); ``` One can say, instead of insisting doing the above, you can write a method which takes an `integer`, `HelloWorld(integer)`, like the following, more easily: ``` int myInt = 32; HelloWorld(myInt); ``` However, I'm just curious whether it's possible or not. If true, is that a good programming practice to add some other functionality to well known classes? PS: I tried to make another class which inherits from `Int32`, but cannot derive from sealed type 'int'.

Original source