声明枚举时,是否应该强制类型为字节以减少 256 个实体? [英] When declaring an enum, should you force the type to byte for under 256 entities?

查看:10
本文介绍了声明枚举时,是否应该强制类型为字节以减少 256 个实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您的应用程序中有一个枚举并且只有几个项目,您是否应该强制底层类型成为可能的最小类型?

If you have an enum in your application and you only have a few items, should you force the underlying type to be the smallest possible type?

    enum smaller : byte
    {
        one,
        two,
        three
    };

推荐答案

没有.不要过早地优化除非您已经用分析器证明这实际上是一个问题.

No. Don't prematurely optimize unless you've proved with a profiler that it's actually a problem.

这篇关于声明枚举时,是否应该强制类型为字节以减少 256 个实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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