Is there a way to initialize an object from a reference class in C#? -
this question has answer here:
- delphi class of in c# 4 answers
in delphi, when want create object
uncertain derived class
, using class of
statement;
tshape = class public procedure draw; end; tcircle = class(tshape) public procedure draw; end; tshapeclassref = class of tshape;
and creating object as;
var ref:tshapeclassref; drawing:tshape; begin ref:=tcircle; drawing:=ref.create; drawing.draw; //this circle object, , draws circle end;
i couldn't find in c#.
use type
this:
public class tshape { }
and:
type t = typeof(tshape);
to initialize object through t
variable, use activator.createinstance(t)
:
shape shp = (shape)activator.createinstance(t);
Comments
Post a Comment