c# 4.0 - What is Activator.CreateInstance? How its working? -
please find below code. can 1 tell me how activator.createinstance working abstract class? have created abstract class, in abstract class have 1 abstract method , inheritted in normal 3 different classes. class mentioned returned correct value, want know how working? advance
using system; using system.collections.generic; using system.linq; using system.text; namespace sample_app { abstract class absclass { public abstract int addtwonumbers(); } class firstclass : absclass { public override int addtwonumbers() { return 1 + 2; } } class secondclass : absclass { public override int addtwonumbers() { return 3 + 2; } } class thirdclass : absclass { public override int addtwonumbers() { return 3 + 2; } } class program { static void main(string[] args) { type classtype = type.gettype("sample_app.firstclass"); absclass obj = activator.createinstance(classtype) absclass; int = obj.addtwonumbers(); } }
}
Comments
Post a Comment