Effective C# – summary

Actually I read a book about effective C# programming. It contains 50 tips.

Reading the first 5 items I decided to summarize most of the 50 tips and to advertise this book.

  1. Use properties instead of accessible data members
  2. Prefer readonly to const
  3. Prefer the is or as operator to casts
  4. Use conditional attributes instead of #if
  5. Always provide .ToString()
  6. Utilize using and try/finally for resource cleanup

Remove an assembly from the global assembly cache (GAC)

You can manage your global assemblies with the gacutil.exe which comes with Microsoft SDK. You can find this tool for instance in folder "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\".

This is an example about removing one assembly:

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe" /u Assembly.To.Uninstall

Howto access a protected method

Here is a small code snippet about howto access a protected method of a class:

Code Snippet
  1. public class OriginalClass
  2. {        
  3.     protected int OrginalProtectedMethod()
  4.     {
  5.         return 0;
  6.     }
  7. }
  8. public class MyDescClass : OriginalClass
  9. {
  10.     public int MyMethod() {
  11.         return OrginalProtectedMethod();
  12.     }
  13. }
  14.  
  15. // access the "protected method"
  16. var md = new MyDescClass();
  17. var result = md.MyMethod();