c# - How to obtain the derived class type from base when calling a method -


ive searched internet , didnt see solution, should simple cant figure out.

i need obtain derived class type within method passes in base class:

class base  { }  class derived1 : base { }  class derived2 : base { }  void somemethod(base obj) {     type basetype = obj.gettype();     type derivedtype = obj.???? }  void main() {     base d1 = new derived1();     base d2 = new derived2();      somemethod(d1);     somemethod(d2); } 

.gettype() returns actual type of current object. doesn't return base type. if somemethod(new derived1()), obj.gettype() return derived1 (seems want).


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -