Home > Enterprise >  Feature 'target-typed object creation' is not available in C# 7.3. Please use language ver
Feature 'target-typed object creation' is not available in C# 7.3. Please use language ver

Time:12-13

I get this error in this line

        MessageParser<BestLimit> parser = new(() => new BestLimit());


Feature 'target-typed object creation' is not available in C# 7.3. Please use language version 9.0 or greater

Can I rewrite the code ?

CodePudding user response:

Unless you're using C# >=9.0 (where target-typed object creation was introduced), you need to specify the type you're creating when using new.

Here's the re-written code:

MessageParser<BestLimit> parser = new MessageParser<BestLimit>(() => new BestLimit());

  • Related