gpt4 book ai didi

c# - 使用 Int32.Parse

转载 作者:行者123 更新时间:2023-11-30 13:29:23 25 4
gpt4 key购买 nike

为什么需要将值(例如 short)转换为字符串,然后再转换为 Int32。为什么short不能转为Int 32?

最佳答案

甚至不需要任何类型的显式转换:

short s = 23;
int k = s;

此外,任何数字文字(没有任何后缀)无论如何都是 int32。

-- 编辑

不需要显式转换的原因是 short 总是小于 int,因此 short 总是完全适合 int 的大小,因此没有潜在的数据丢失。

关于c# - 使用 Int32.Parse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1365804/

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