有什么理由在C#中使用byte / short等.. [英] Any reason to use byte/short etc.. in C#?

查看:135
本文介绍了有什么理由在C#中使用byte / short等..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在int类型上?

很多代码使用int和double / floats。

A lot of code either uses int with double/floats.

我知道有一些.NET移动版本,所以字节/短路自成一体,但桌面应用程序有什么意义吗?

I know there is the likes of .NET mobile versions so byte/short comes into their own but for desktop apps is there any point?

当我做C ++工作时(游戏)编程)我非常清楚我使用的每种数据类型虽然我在C#/ Java工作中没有这种感觉。

When I did C++ work (Games programming) I was very aware of each data type I was using though I don't have this feeling in C#/Java work.

我会有什么好处使用一个字节说如果我知道我的循环永远不会超过字节的边界?

Would there be any benefit of me using a byte say if I know my loop will never go over the bounds of byte?

推荐答案

单个 byte long 相比,内存不会产生巨大差异,但是当你开始拥有大型数组时,这7个额外字节将会产生一个很大的区别。

A single byte compared to a long won't make a huge difference memory-wise, but when you start having large arrays, these 7 extra bytes will make a big difference.

更重要的是数据类型有助于更好地传达开发人员的意图:当你遇到字节长度时; 你肯定知道长度的范围是字节

What's more is that data types help communicate developers' intent much better: when you encounter a byte length; you know for sure that length's range is that of a byte.

这篇关于有什么理由在C#中使用byte / short等..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆