0

I have a Visual Studio 2017 project and want to open it with Visual Studio 2015.

In my C# code I use this method

    public static bool TryGetValue(this CustomProperties props, string key, out string value)
    {
        try
        {
            CustomProperty prop = props[key];
            value = prop.Value;
            return true;
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            value = string.Empty;
            return false;
        }
    }

to get a value from a collection. When building the project I get invalid expression terms.

When I use this line of code

        if (props.TryGetValue("username", out string username)) // string is an invalid expression
        {
            edtUsername.Text = username; // this is unknown because the expression above throws errors
        }

Visual Studio 2015 says that "string" is an invalid expression. How can I fix this?

2
  • You mean this code compiles successful in VS2017? Commented Dec 20, 2018 at 13:38
  • 1
    Don't use Visual Studio 2015. out string username is a C# 7 feature. You can't use C# 7 in VS 2015 Commented Dec 20, 2018 at 13:48

1 Answer 1

1

declare string variable outside of out operator

string username;
if (props.TryGetValue("username", out username)) 
{
    edtUsername.Text = username; 
}
Sign up to request clarification or add additional context in comments.

1 Comment

This reverts to C# 6, it doesn't make VS 2015 work with C# 7