gpt4 book ai didi

C#,无法将类型 `long' 隐式转换为 `uint'

转载 作者:太空宇宙 更新时间:2023-11-03 21:14:18 35 4
gpt4 key购买 nike

这有什么问题吗?我在前两行收到错误。

bounds.xMin = (Mathf.FloorToInt (x / GridSize) * GridSize);
bounds.yMin = (Mathf.FloorToInt (y / GridSize) * GridSize);
bounds.xMax = bounds.xMin + GridSize;
bounds.yMax = bounds.yMin + GridSize;

bounds.xMinbounds.yMinxyGridSize 都是 uint 类型。

最佳答案

你所有的变量都是uint,但是Mathf.FloorToInt的返回类型是 int

要将 uint 乘以 int,C# 会将两个操作数都转换为 long,因为它是唯一可以表示所有操作数的整数类型他们可能的值(value)。此操作的结果也将是 long

您需要将整个结果或至少是 Mathf.FloorToInt 的结果转换为 uint

来自 C# 语言规范:

For the binary +, –, *, /, %, &, ^, |, ==, !=, >, <, >=, and <= operators, the operands are converted to type T, where T is the first of int, uint, long, and ulong that can fully represent all possible values of both operands. The operation is then performed using the precision of type T, and the type of the result is T

关于C#,无法将类型 `long' 隐式转换为 `uint',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35497449/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com