为什么不使用无符号变量,更多的时候?变量、符号、时候、更多

2023-09-04 12:46:29 作者:ゞ灬.搂空的拥抱

看来,无符号整数将是方法参数和类成员不应该负有用的,但我没有看到很多人写$ C C这样$。我试了一下自己,发现需要从int强制转换为UINT有点讨厌...

总之你有什么想法吗?

复制

  

为什么数组长度的诠释,而不是UINT?

解决方案

使用标准的人很可能避免了铸件的无符号的。在您的code,你也许可以保持区别确定,但很多其他的投入和第三方库惯于从而铸造只会开车的人疯了!

It seems that unsigned integers would be useful for method parameters and class members that should never be negative, but I don't see many people writing code that way. I tried it myself and found the need to cast from int to uint somewhat annoying...

二进制无符号整数是什么意思

Anyhow what are you thoughts on this?

Duplicate

Why is Array Length an Int and not an UInt?

解决方案

Using the standard ones probably avoids the casting to unsigned versions. In your code, you can probably maintain the distinction ok, but lots of other inputs and 3rd party libraries wont and thus the casting will just drive people mad!