Using C# Extension for enum, int, bool, etc

4/1/2014·1 min read

Using C# extension can extend your existing C# type, method's function.

1. Example: extend bool's function. (at same namespace)

write extension class to the same namespace. Then, you can simply call flg.Int().

2. Example: add your extension class to other shared project

There's case you access extension logic from different project, other DLL. Then, you just need to add Using to your class. See following example...

1) so first you add extension logic to shared Product [ClassLibrary1]

2) then when you want to access your extension logic, add reference to your project and add namespace to the class

I used case is adding extension to Enum class, for example, depend on enum's value return different name(string).

if you want to download above sample, click following button, then you can download sample application