[软文备份] Converting to int16, int32, int64 – how do you know which one to choose?

[软文备份 .net]

Everyone here who has mentioned that declaring an Int16 saves ram should get a downvote.

The answer to your question is to use the keyword “int” (or if you feel like it, use “Int32″).

That gives you a range of up to 2.4 billion numbers… Also, 32bit processors will handle those ints better… also (and THE MOST IMPORTANT REASON) is that if you plan on using that int for almost any reason… it will likely need to be an “int” (Int32).

In the .Net framework, 99.999% of numeric fields (that are whole numbers) are “ints” (Int32).

Example: Array.Length, Process.ID, Windows.Width, Button.Height, etc, etc, etc 1 million times.

EDIT: I realize that my grumpiness is going to get me down-voted… but this is the right answer.

by Timothy Khouri

http://stackoverflow.com/questions/270263/converting-to-int16-int32-int64-how-do-you-know-which-one-to-choose

另一篇中文,解释的也非常 清晰:

http://kb.cnblogs.com/page/71981/

此条目发表在 .net, 实验室 分类目录,贴了 标签。将固定链接加入收藏夹。