我需要存储大量数据。 我需要识别“null”+ 0-3。 基本上我需要区分5个身份。 例如“无”,“向左”,“向上”,“向右”,“向下”。 在C#中存储这个的好方法是什么? 目前我认为它可能是sbyte但我希望一个“更小”的解决方案。
I need to store huge amounts of data. I need to identify "null" + 0-3. Basically i need to differentiate between 5 identities so to say. For example "nothing", "left", "up", "right", "down". What is a good way to store this in C#? At the moment i think it could be sbyte but i hope for a "smaller" solution.
最满意答案
sbyte / byte是C#中的最小单位,除非您创建自己的数据结构,例如使用一个值来存储多个项目,例如使用3位位置来存储一个项目,因此Int16可以存储5个项目。
换句话说,如果不追求空间效率的极端,建议使用枚举来存储有意义的值,并且可以使用byte作为枚举,以便节省空间:
enum Direction : byte {Nothing=0, Left, Up, Right, Down};这将使代码更清晰。
sbyte / byte is the smallest unit in C# unless you make your own data structure such as use one value to store multiple items, like use 3 bit positions to store one item so Int16 can store 5 items.
In another way, if not pursue the extreme of space efficiency, enum is more recommended to store meaningful values, and you can use byte for an enum so that save the space:
enum Direction : byte {Nothing=0, Left, Up, Right, Down};That will make the code much clearer.
更多推荐
发布评论