string strValue = "10";
int iValue = Convert.ToInt16(strValue);
int iValue = Convert.ToInt16(strValue);
解决方案 »
- 求指教
- WinForm里怎么使用Http把数据发送到WebService里
- Winform关于跨线程问题变量.请以代码见真章.
- 一个让人蛋疼的面试题啊
- 关于 【COMBOBOX 】 的数据过滤问题 请教一下高玩!
- image怎么缩小图片后显示?
- Shell32.Folder 在那里空间名下面
- 怎样将对DataGridView的修改映射到其数据源中?
- 我把excel文件的内容导入到sqlserver中去,调试成功,但是column的顺序乱掉了,而且column的类型是varchar的,但是导进去后20050606的值
- ole for oracle的问题,分不够再加!!!!!!!
- 第一次查询正常,第二次查询就会多查询数据一次,第三次再点击按钮查询的时候又会查询三次,奇怪了!那为给麻烦看看原因!!
- Console.WriteLine打印中文为何出乱码?
string value = "10";
int iValue = Convert.ToInt16(value); string value2 = "10";
object obj = value2;
int objValue = (int)obj;
1.编译exe
2.运行ildasm(2012 版):start -> vs -> visual studio Tools -> developer command prompt for vs2012
3.运行命令:ildasm D:\A.exe //exe 路径
4.在IL DASM 里,双击Main,可以看到:
IL_0000: nop
IL_0001: ldstr "10"
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: call int16 [mscorlib]System.Convert::ToInt16(string)
IL_000d: stloc.1
IL_000e: ldstr "10"
IL_0013: stloc.2
IL_0014: ldloc.2
IL_0015: stloc.3
IL_0016: ldloc.3
IL_0017: unbox.any [mscorlib]System.Int32
IL_001c: stloc.s V_4
IL_001e: ret在0008,可以看到调用了Convert的ToInt方法,
在0017处,发生了拆箱....
{
if (value == null)
{
return 0;
}
return short.Parse(value, CultureInfo.CurrentCulture);
}public static short Parse(string s, IFormatProvider provider)
{
return Parse(s, NumberStyles.Integer, NumberFormatInfo.GetInstance(provider));
}private static short Parse(string s, NumberStyles style, NumberFormatInfo info)
{
int num = 0;
try
{
num = Number.ParseInt32(s, style, info);
}
catch (OverflowException exception)
{
throw new OverflowException(Environment.GetResourceString("Overflow_Int16"), exception);
}
if ((style & NumberStyles.AllowHexSpecifier) != NumberStyles.None)
{
if ((num < 0) || (num > 0xffff))
{
throw new OverflowException(Environment.GetResourceString("Overflow_Int16"));
}
return (short) num;
}
if ((num < -32768) || (num > 0x7fff))
{
throw new OverflowException(Environment.GetResourceString("Overflow_Int16"));
}
return (short) num;
}