The following won't compile (missing a cast)
TypeScript |
The following, compiles but has a run time error:
C# |
TypeScript |
C# |
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Shane Poppleton5 reputationPosted Jun 10, 2009, 7:45 PM EDT
I have a workaround, i will post here in case anyone has the same problem.
I added a second type parameter to the class and pass in the derived type so that my CreateMe() method knows what type to return.
class Program { static void Main(string[] args) { foo f = foo.CreateMe(); } } class foo : GenericTest { } class bar { } class GenericTest where U:new() { public static U CreateMe() { return new U(); } }