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?

1 Answers1

1

declare string variable outside of out operator

string username;
if (props.TryGetValue("username", out username)) 
{
    edtUsername.Text = username; 
}
Yehor Androsov
  • 4,885
  • 2
  • 23
  • 40