为什么我们应该使用int而不是 short 或者 byte?

2018/04/24 204

运行时优化32位整数类型(Int32和UInt32)的性能,因此将这些类型用于计数器和其他频繁访问的整型变量。

对于浮点操作,Double是最有效的类型,因为这些操作是通过硬件优化的。

From the book: MCTS Self-Paced Training Kit (Exam 70-536): Microsoft® .NET Framework 2.0—Application Development Foundation

Chapter 1: "Framework Fundamentals"

Lesson 1: "Using Value Types" Best Practices: Optimizing performance with built-in types The runtime optimizes the performance of 32-bit integer types (Int32 and UInt32), so use those types for counters and other frequently accessed integral variables. For floating-point operations, Double is the most efficient type because those operations are optimized by hardware.

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

来自 https://stackoverflow.com/questions/129023/net-integer-vs-int16?noredirect=1&lq=1

评论