<p>I've been a professional software engineer for about a year now, having graduated with a CS degree. I've known about assertions for a while in C++ and C, but had no idea they existed in C# and .NET at all until recently.</p>

<p>Our production code contains no asserts whatsoever and my question is this...</p>

<p>Should I begin using Asserts in our production code? And if so, When is its use most appropriate? Would it make more sense to do</p>

<pre><code>Debug.Assert(val != null);
</code></pre>

<p>or</p>

<pre><code>if ( val == null )
    throw new exception();
</code></pre>

Put
```
Debug.Assert()
```
everywhere in the code where you want have sanity checks to ensure invariants. When you compile a Release build (i.e., no
```
DEBUG
```
compiler constant), the calls to
```
Debug.Assert()
```
will be removed so they won't affect performance.
You should still throw exceptions before calling
```
Debug.Assert()
```
. The assert just makes sure that everything is as expected while you're still developing.