If you are using VS 2010 Premium or higher, check out the Code Contracts Static Analyzer. If you use Code Contracts statements in your code, it will statically analyze your statements and try to prove whether they are true.
Pex is also extremely interesting (for unit testing), although I have not played with it enough yet to find out how useful this will be. I tried to run it in the Parse procedure for one of my custom value types, and his research found a number of angular cases that I did not consider.
Dan bryant
source share