UInt16的数组,C#中的后缀是什么?

发布于 2024-12-14 07:11:57 字数 279 浏览 3 评论 0原文

我正在尝试初始化内联 UInt16 数组。对于 int 我可以执行以下操作:

int[] int_array = new[]{0,0,0,0};

同时使用 UInt16 在没有强制转换的情况下无法工作:

UInt16[] uint16_array= new[]{(UInt16)0,(UInt16)0};

这些强制转换非常烦人。 我想知道 C# 中是否有任何后缀来消除分配的歧义(例如浮点数的 0.0f)。

I'm trying to initialize inline an array of UInt16. For int I can do the following:

int[] int_array = new[]{0,0,0,0};

meanwhile using UInt16 doesn't work without a cast:

UInt16[] uint16_array= new[]{(UInt16)0,(UInt16)0};

It's quite annoying do those casts.
I was wondering if there is any suffix in C# to disambiguate the assignment (like 0.0f for float).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

情丝乱 2024-12-21 07:11:57

我认为没有,但你为什么不这样做呢

UInt16[] uint16_array= new UInt16[] { 0, 0, 0, 0 };

I don't think there is one, but why don't you do this instead

UInt16[] uint16_array= new UInt16[] { 0, 0, 0, 0 };
厌味 2024-12-21 07:11:57

C# 没有无符号 16 位整数的类型后缀。 VB.NET 确实如此,仅供参考:

Dim number As UShort = 8US

这里是 另一个资源列出了不同的后缀。

C# doesn't have a type suffix for unsigned 16-bit integers. VB.NET does though, just for reference:

Dim number As UShort = 8US

Here's another resource that lists the different suffixes.

慵挽 2024-12-21 07:11:57

这是比科里的更短的方法:(

ushort[] uint16_array = { 0, 0, 0, 0 };

或)

UInt16[] uint16_array = { 0, 0, 0, 0 };

Here's an even shorter way than Corey's:

ushort[] uint16_array = { 0, 0, 0, 0 };

(or)

UInt16[] uint16_array = { 0, 0, 0, 0 };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文