Class of

  • Thread starter Thread starter Alexander Muylaert
  • Start date Start date
A

Alexander Muylaert

Hi

In delphi I can do the following


TMyThing = class(Tobject)

TMyThing2 = class(TMyThing);
TMyThing3 = class(TMyThing);
TMyThing4 = class(TMyThing);

TMyThingClass = class of TMyThing;


function MakeThing(aClass : TMyThingClass) : TMyThing;
begin
result := aClass.Create;
end;

Can I do this in C#. I assume I can do something like this and what is the
syntax.

Kind regards

Alexander
 
Alexander Muylaert said:
In delphi I can do the following


TMyThing = class(Tobject)

TMyThing2 = class(TMyThing);
TMyThing3 = class(TMyThing);
TMyThing4 = class(TMyThing);

TMyThingClass = class of TMyThing;


function MakeThing(aClass : TMyThingClass) : TMyThing;
begin
result := aClass.Create;
end;

Can I do this in C#. I assume I can do something like this and what is the
syntax.

Use typeof(Foo) to get a Type reference, and use
Activator.CreateInstance to create an instance of a type.
 
Thanks a lot.

Kind regards

Alexander


Jon Skeet said:
Use typeof(Foo) to get a Type reference, and use
Activator.CreateInstance to create an instance of a type.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top