After upgrading to VS 2017 I got the following error from this code (which has always been working perfectly)
byte[] HexStringToByteArray(string hex)
{
if (hex.Length % 2 == 1)
throw new Exception("The binary key cannot have an odd number of digits");
byte[] arr = new byte[hex.Length >> 1];
for (int i = 0; i < hex.Length >> 1; ++i) // Error in this line
{
arr[i] = (byte)((GetHexVal(hex[i << 1]) << 4) + (GetHexVal(hex[(i << 1) + 1])));
}
return arr;
}
Exception:
Error 1: The variable 'i' cannot be used with type arguments
Error 2: 'hex' is a variable but is used like a type
the solution was to surround the expression by parentheses.
for (int i = 0; i < (hex.Length >> 1); ++i)
But that made me wonder is this a bug or a new functionality? Thanks.
Thanks for reporting this. This is a confirmed regression in the precedence of parsing. This fix will ship in the first quarterly release of VS2017 at the latest.
Information on the fix: https://github.com/dotnet/roslyn/pull/16834