简体   繁体   中英

Visual Studio 2019: C# Version

I just recently started back into C# and installed Visual Studio 2019 on APRIL 14,2021.

I started a new .NET Core Windows Forms App targeting Core Framework 4.7.2

I was starting to do some work with basic database connections:

I used the following:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;


In my Form_1 Load section:


using SqlCommand command = new SqlCommand(AMZN_select, AMZN_Connection);


I get an error:

"Feature 'usings declarations' is not available in C#7.3. Please use language 8.0 or greater"

So my question: I installed this version a few days ago in 2021. We are on version 9.0 I think for C#. I was assuming that a new project in 2021 would automatically taregt at least C#8, not C#7.3.

When I search the Google machine for this error I see people editing configuration files? Seriously? Thats how you target the correct C# version in a completely new project? I am willing to start from scratch and restart the project and open a new project but can I target the LATEST available C# version from the creation of the project. Again, I thought targeting a 4.xx framework would automatically get me C# version 8.0

What am I missing.

If I have to edit a config file can someone tell me what file I have to edit. I just can't believe the IDE allows me to create a project, get started and then tell me I am not targeting a current version of C#.

Again, I am returning to Visual Studio after 5 years but I don't remember having this issue back then.

OK heres what I found:

When I created the app I used:

在此处输入图像描述

Apparently you have to use:

在此处输入图像描述

I read the descriptions of the two and they seem virtually identical but apparently not.

One allows me to use:

'using'

UPDATE:

在此处输入图像描述

So the choice is grayed out depending on how you began the project.

C# 7.3 is the last C# version targeting .NET Framework. Newer language versions are only available for .NET Core 3, .NET 5 or .NET Standard 2.1.

See https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM