title: Casting an object to a Type and use a method
body: <p>Let's say i have an abstract class ObjectA. ObjectC and ObjectB inherit from ObjectA. There are a lot more that inherit from ObjectA.</p>
  
  <p>Then, I have methods that do something according to the type of the object.</p>
  
  <pre><code>public void DoSomething(ObjectC data){}
  public void DoSomething(ObjectB data){}
  </code></pre>
  
  <p>I was wondering if there's a way to call the method that i need according to the type of the object, that's because i don't know what kind of Object i will get.</p>
  
  <pre><code>public void DoSomething(ObjectA data){
      DoSomething(data);
  }
  </code></pre>
  
  <p>Currently i am using</p>
  
  <pre><code>public void DoSomething(ObjectA data){
      if (data is ObjectB dataB){
          DoSomething(dataB);
      }else if (data is ObjectC dataC){
          DoSomething(dataC);
      }
  }
  </code></pre>
  
  <p>I was wondering if there's a way to avoid the usage of a <code>if/else</code>.</p>
  
  <p>Thanks.</p>