Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feature Recursive Patterns Is currently in Preview Version of Vs Code

I am unable to use some piece of code introduced in c# version 8.0.

Consider this piece of code.

Property patterns

class Address
{

    public string State { get; set; }
}

public static decimal ComputeSalesTax(Address location, decimal salePrice) =>
location switch
{
    { State: "WA" } => salePrice * 0.06M,
    { State: "MN" } => salePrice * 0.75M,
    { State: "MI" } => salePrice * 0.05M,
    // other cases removed for brevity...
    _ => 0M
};

Error:

enter image description here

Please help me solve this , infact I am using latest version of vs code.

like image 306
TAHA SULTAN TEMURI Avatar asked Jul 27 '19 10:07

TAHA SULTAN TEMURI


People also ask

What is recursive pattern matching in functional programming?

Folks who have worked with functional languages will probably be familiar with the concept behind the recursive pattern matching C# 8 language feature. This technique can be used to validate and inspect objects more easily based on their shape.

How to use preview features in Visual Studio?

To use Preview features, use the 'preview' language version. Show activity on this post. In Project → Properties → Build Select Advanced… (Advanced Build Settings) Show activity on this post. I my case I needed to check this checkbox (and restart Visual Studio!)

Why does the list of preview features fluctuate for each release?

As we continue to iterate on these features, the list of preview features will fluctuate for each Visual Studio release as some features get added into the product and others are cut. You can learn more about the preview features available in each release in the release notes. Comments are closed.

What's new in Visual Studio 2019 Preview 2?

Visual Studio 2019 Preview 2 is out! And with it, a couple more C# 8.0 features are ready for you to try. It’s mostly about pattern matching, though I’ll touch on a few other news and changes at the end. When C# 7.0 introduced pattern matching we said that we expected to add more patterns in more places in the future. That time has come!


1 Answers

You need to tell VS Code that you want to use a newer (preview) language version of c#. Are you working on a project? If so you can put <LangVersion>preview</LangVersion> in the .csproj file. This might resolve the issue. You need to put it in the right place however.

like image 103
Joelius Avatar answered Oct 02 '22 22:10

Joelius