int y = -2147483648;
int z = unchecked(y / -1);
Run Code Online (Sandbox Code Playgroud)
第二行引起了OverflowException.不应该unchecked阻止这个?
例如:
int y = -2147483648;
int z = unchecked(y * 2);
Run Code Online (Sandbox Code Playgroud)
不会导致例外.
我有什么理由不能使用以下代码吗?
ulong test(int a, int b)
{
return a == b ? 0 : 1;
}
Run Code Online (Sandbox Code Playgroud)
它告诉我:
Cannot implicitly convert type 'int' to 'ulong'. An explicit conversion exists (are you missing a cast?)
Run Code Online (Sandbox Code Playgroud)
以下将有效:
ulong test(int a, int b)
{
return false ? 0 : 1;
}
Run Code Online (Sandbox Code Playgroud)
我知道如何解决这个问题.我只是想知道原因.
谢谢.
我正在使用以下方法复制图像的一部分imagescale:
$img = imagecreatefromjpeg('before.jpg');
$img = imagescale($img, 660, 384);
Run Code Online (Sandbox Code Playgroud)
之前:

后:

使用颜色较少的图像.