title: Using Case/Switch and GetType to determine the object
body: <blockquote>
  <p><strong>Possible Duplicate:</strong><br />
  <a href="https://stackoverflow.com/questions/298976/c-sharp-is-there-a-better-alternative-than-this-to-switch-on-type">C# - Is there a better alternative than this to ‘switch on type’?</a></p>
  </blockquote>
  
  <p>If you want to <code>switch</code> on a type of object, what is the best way to do this?</p>
  <h3>Code snippet</h3>
  <pre><code>private int GetNodeType(NodeDTO node)
  {
      switch (node.GetType())
      { 
          case typeof(CasusNodeDTO):
              return 1;
          case typeof(BucketNodeDTO):
              return 3;
          case typeof(BranchNodeDTO):
              return 0;
          case typeof(LeafNodeDTO):
              return 2;
          default:
              return -1;
      }
  }
  </code></pre>
  <p>I know this doesn't work that way, but I was wondering how you could solve this.
  Is an <code>if/else</code> statement appropriate in this case?</p>
  <p>Or do you use the switch and add <code>.ToString()</code> to the type?</p>