title: Best way to determine if an instance is of a specific type
body: <p>I'm working on a C# project, and I found myself with this situation:</p>
  
  <pre><code>TypeCode code = value == null ? TypeCode.DBNull : TypeCode.GetTypeCode(value.GetType());
  
  switch(code) {
      case TypeCode.DBNull: data = SerializeNull(); break;
      case TypeCode.String: data = SerializeString((String) value); break;
      case TypeCode.Int32: data = SerializeInt32((Int32) value); break;
      // ... MORE TYPES
  }
  </code></pre>
  
  <p>My question is:</p>
  
  <p>Is there any advantage of using this "type determination" technique over this one?:</p>
  
  <pre><code>if(value == null) data = SerializeNull();
  else if(value is String) data = SerializeString((String) value);
  else if(value is Int32) data = SerializeInt32((Int32) value);
  </code></pre>
  
  <p>As for my opinion, I find the last one more readable and easy to implement.</p>
  
  <p>I still wanted to know if maybe there's a performance issue</p>
  
  <p>Thanks in advance</p>