In delphi I can declare a type of class like so
type
TFooClass = class of TFoo;
TFoo=class
end;
Which is the C# equivalent for this declaration?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The closest you can get in C# is the
Typetype, which contains the metadata about a type.It’s not exactly the same. In Delphi, “type of othertype” is itself a type that you can assign to a variable. In C# “type of othertype” is a
System.Typeinstance that can be assigned to any variables of typeSystem.Type.As an example, in Delphi, you can do this:
You cannot do anything like this in C#; you cannot call static methods of type A from instances of
Typethat happen to holdtypeof(A), nor can you define a variable that can only holdtypeof(A)or derived types.(Some specific patterns that Delphi metaclass types are used for, can be accomplished using generics:
In this case, T is the “type of A” or whatever derived class of A was used to construct the class.)