升级到VS 2017后,我从此代码中得到以下错误(一直运行良好)
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;
}
Run Code Online (Sandbox Code Playgroud)
例外:
Error 1: The variable 'i' cannot be used with type arguments
Error 2: 'hex' is a variable but is used like a type
Run Code Online (Sandbox Code Playgroud)
解决方案是用括号括起表达式.
for (int i = 0; i < (hex.Length >> 1); ++i)
Run Code Online (Sandbox Code Playgroud)
但这让我想知道这是一个错误还是一个新功能?谢谢.
| 归档时间: |
|
| 查看次数: |
678 次 |
| 最近记录: |