Share via

.netframework update difficulties

Misha 1 Reputation point
2021-12-19T08:14:42.737+00:00

I wanted to use new(), but it's only allowed in 4.9. So i downloaded latest sdk, but i still can't change to 4.9. my highest version possible right now is 4.8.

Developer technologies | .NET | Entity Framework Core
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


2 answers

Sort by: Most helpful
  1. Karen Payne MVP 35,606 Reputation points Volunteer Moderator
    2021-12-19T11:03:10.437+00:00

    The minimal requirement for using new() is Visual Studio 2019 setup for C#9. When creating a new project in VS2019 the default Framework is .NET Core 5. To get to C#9, double click the project file in solution explorer and make sure LangVersion as shown below. If you use latest rather than 9 and have .NET 5 and 6, this will not work unless you enable experimental features and even so there are complications so use 9 for LangVersion.

    Note if you go to VS2022 you can not build for x86, only x64.

    <Project Sdk="Microsoft.NET.Sdk">  
      
      <PropertyGroup>  
    	  <LangVersion>9.0</LangVersion>  
    	  <TargetFramework>net5.0</TargetFramework>  
      </PropertyGroup>  
      
    </Project>  
    

    If using windows forms, <TargetFramework>net5.0-windows</TargetFramework>

    Was this answer helpful?

    0 comments No comments

  2. Viorel 127K Reputation points
    2021-12-19T09:41:52.71+00:00

    It seems that target-typed new expressions is offered in C# 9, which is available in .NET 5 (also named “Core”), but not in .NET Framework. Try using Visual Studio 2022. Create a “Console App” project instead of “Console App (.NET Framework)”. Specify .NET 5 or 6. (Maybe it works in Visual Studio 2019 too).

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.