Después de actualizar a VS 2017, recibí el siguiente error de este código (que siempre ha funcionado perfectamente)
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; }
Excepción:
Error 1: The variable 'i' cannot be used with type arguments Error 2: 'hex' is a variable but is used like a type
la solución fue rodear la expresión entre paréntesis.
for (int i = 0; i < (hex.Length >> 1); ++i)
Pero eso me hizo preguntarme si esto es un error o una nueva funcionalidad. Gracias.
Gracias por informar esto. Esta es una regresión confirmada en la precedencia del análisis. Esta solución se enviará en la primera versión trimestral de VS2017 a más tardar.
Información sobre la corrección: https://github.com/dotnet/roslyn/pull/16834