.NET整数VS Int16的? [英] .NET Integer vs Int16?

查看:189
本文介绍了.NET整数VS Int16的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可疑的编码实践。

I have a questionable coding practice.

当我需要遍历的少数商品列表的数量限制为在 32000 ,我用的Int16 我的的变量类型,而不是整数。我这样做是因为我想用的Int16 比一个完全成熟的更有效的整数

When I need to iterate through a small list of items whose count limit is under 32000, I use Int16 for my i variable type instead of Integer. I do this because I assume using the Int16 is more efficient than a full blown Integer.

难道我错了吗?是否有使用的Int16 VS的整数之间没有有效的性能差异?我应停止使用的Int16 和公正的坚持与整数为我所有的计数/迭代的需求?

Am I wrong? Is there no effective performance difference between using an Int16 vs an Integer? Should I stop using Int16 and just stick with Integer for all my counting/iteration needs?

推荐答案

根据下面的参考,运行的优化的的Int32 性能,因此建议他们柜台等频繁访问的操作。

According to the below reference, the runtime optimizes performance of Int32 and recommends them for counters and other frequently accessed operations.

这本书: MCTS自学培训工具包(考试70-536):微软.NET Framework 2.0的应用程序开发基础

第1章:框架基础
第1课:使用值类型

Chapter 1: "Framework Fundamentals"
Lesson 1: "Using Value Types"

最佳实践:优化性能   与内置类型

Best Practices: Optimizing performance with built-in types

运行时优化的32位整数类型(的Int32和UInt32)将性能,因此使用这些类型的计数器和其他经常访问的不可或缺的变量。

有关浮点运算,双是最有效的类型,因为这些操作是通过硬件进行了优化。

For floating-point operations, Double is the most efficient type because those operations are optimized by hardware.

另外,表1-1中推荐的相同部分列出了使用每种类型。 与此相关的讨论:

Also, Table 1-1 in the same section lists recommended uses for each type. Relevant to this discussion:

  • 的Int16 - 互操作和其他专业用途
  • 的Int32 - 全数字和计数器
  • 的Int64 - 大整数

这篇关于.NET整数VS Int16的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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