Using "as bool?" instead of "object something = ViewState["hi"]"
<p>So I'm going through old code (2.0) and I came across this:</p>

<pre><code>object isReviewingValue = ViewState["IsReviewing"];

if (isReviewingValue is bool)
{
  return (bool)isReviewingValue;
}
</code></pre>

<p>My first thought was to us the "as" keyword to avoid the unneeded </p>

<pre><code>(bool)isReviewingValue;
</code></pre>

<p>But "as" only works with non value types.  No problem, I just went ahead and did this:</p>

<pre><code>bool? isReviewingValue= ViewState["IsReviewing"] as bool?;
if (isReviewingValue.HasValue)
{
  return isReviewingValue.Value;
}
</code></pre>

<p>Question is:  Besides looking a bit more readable, is this in fact better?</p>

<p>EDIT:</p>

<pre><code>public Stopwatch AsRun()
{
  Stopwatch watch = new Stopwatch();

  watch.Start();
  for (Int32 loopCounter = 0; loopCounter &lt; 10000; loopCounter++)
  {
    Object value = true;
    Boolean? test = value as Boolean?;
    if (test.HasValue)
    {
      Boolean something = test.Value;
    }
  }
  watch.Stop();

  return watch;
}

public Stopwatch ObjectIsRun()
{
  Stopwatch watch = new Stopwatch();

  watch.Start();
  for (Int32 loopCounter = 0; loopCounter &lt; 10000; loopCounter++)
  {
    Object test = true;
    if (test is Boolean)
    {
      Boolean something = (Boolean)test;
    }
  }
  watch.Stop();

  return watch;
}
</code></pre>

<p>Answer:  Turns out that with the above methods run in a test fashion, the original code is about 10 times faster.</p>
