How to use C # 7+ syntax in Visual Studio 2017

Source: Internet
Author: User

Objective

I didn't know any of my predecessors ' posts. C # 7 console began to support the execution of asynchronous methods, and then idle to nothing, engage, do not get out, and then wrote this blog, do not like to spray, may be helpful to you.

Support for the C # 7+ syntax in visual Studio 2017 configuration

I thought I was VS2017. It must support C # 7+ syntax, then change the console program to asynchronous, and then tell me no, no, it's not nonsense, this is the following:

     Public classProgram { Public Static AsyncTask Main (string[] args) {            using(varContext =NewEfcoredbcontext ()) {                varBlog =awaitContext. Blogs.findasync (3); Blog. Name="Jeffcky"; varresult =awaitcontext.            Savechangesasync ();        } console.readkey (); }    }

Then I learned that the. NET Framework 4.7 can use C # 7 syntax, thinking that is not installed in the. NET Framework 4.7, and then to the following address download the. NET Framework 4.7 (https://www.microsoft.com/ zh-cn/download/details.aspx?id=55170), as a result of an installation, it tells me to install or a later version:

Then one finds out that the C # 7 syntax is supported in Visual Studio Update 3, and I now have more than one version of Visual Studio 2017 that I don't know much about, and then I see the Epiphany:

Okay, here it is. My vs 2017 already supports C # 7 syntax, which seems to be missing any settings, so look at the following scenario.

(1) Right-click the project solution Tap Properties.

(2) Click "Generate" in the Left tab, there is an "advanced" click in the bottom right corner of the interface, as follows:

Originally the language version is the latest major version of the "default", that should not be the highest version, open the drop-down list, choose the version we want, you can play happily, as follows:

Or we manually edit the project file with. csproj to find the following:

<propertygroup condition="">    <platformtarget>anycpu</ Platformtarget>    <DebugSymbols>true</DebugSymbols>    <debugtype>full</ Debugtype>    <Optimize>false</Optimize>    <outputpath>bin\debug\</ Outputpath>    <DefineConstants>DEBUG; trace</defineconstants>    <ErrorReport>prompt</ErrorReport>    <WarningLevel> 4</WarningLevel>    <LangVersion>default</LangVersion>  </ Propertygroup>

It would be a langversion to modify our corresponding version like:<langversion>7.2</langversion> Save, and then build the solution.

Summarize

In theory vs 2017 should not use the highest C # syntax version, but this is not the case, so if you are experiencing this problem, first make sure that you have the. NET Framework 4.7 installed, and that you can use async methods in the console and corresponding C # 7+ syntax if you have installed the method described above. May be I know too little, write out perhaps to do not know the children's shoes have some help, already knew the big guys will skip, we'll see you next time.

How to use C # 7+ syntax in Visual Studio 2017

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.