转换为int16,int32,int64 - 您如何知道选择哪一个? [英] Converting to int16, int32, int64 - how do you know which one to choose?

查看:421
本文介绍了转换为int16,int32,int64 - 您如何知道选择哪一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常需要转换一个检索值(通常作为字符串) - 然后将其转换为int。但是在C#(。Net)中你必须选择int16,int32或int64 - 当你不知道你的检索数量有多大时,你怎么知道选择哪一个?

I often have to convert a retreived value (usually as a string) - and then convert it to an int. But in C# (.Net) you have to choose either int16, int32 or int64 - how do you know which one to choose when you don't know how big your retrieved number will be?

推荐答案

此处提到声明Int16保存ram的所有人都应该得到一个downvote。

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

您的问题的答案是使用关键字int(或者如果您愿意,请使用Int32)。

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

你的数字范围高达24亿......而且,32位处理器可以更好地处理这些内容...而且(如果你计划使用那个int几乎是最重要的原因)任何原因......它可能需要是一个int(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).

在.Net框架中,99.999%的数字字段(即整数) )是ints(Int32)。

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

示例:Array.Length,Process.ID,Windows.Width,Button.Height等等100万次。

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

编辑:我意识到我的脾气暴躁会让我失望......但这是正确的答案。

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

这篇关于转换为int16,int32,int64 - 您如何知道选择哪一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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