小编Mar*_*ner的帖子

为什么将int.MinValue除以-1会在未经检查的上下文中抛出OverflowException?

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)

不会导致例外.

c# unchecked checked overflowexception

46
推荐指数
3
解决办法
2116
查看次数

在inline-if中返回ulong

我有什么理由不能使用以下代码吗?

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)

我知道如何解决这个问题.我只是想知道原因.

谢谢.

c# ternary-operator conditional-operator ulong

6
推荐指数
1
解决办法
153
查看次数

imagescale无法正常工作

我正在使用以下方法复制图像的一部分imagescale:

$img = imagecreatefromjpeg('before.jpg');
$img = imagescale($img, 660, 384);
Run Code Online (Sandbox Code Playgroud)

之前: 在imagescale之前

后: 在图像尺度之后

使用颜色较少的图像.

php gd image

3
推荐指数
1
解决办法
1595
查看次数