Convert.ToInt16 与 Convert.ToInt32 究竟区别在哪里?

koukoujiayi 2008-09-10 10:28:44
Convert.ToInt16 与 Convert.ToInt32 除了16位和32位外,还有区别在哪里?
...全文
1201 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
初级程序员 2011-09-14
  • 打赏
  • 举报
回复
学习。
busymj 2008-09-10
  • 打赏
  • 举报
回复

其它一样的。
busymj 2008-09-10
  • 打赏
  • 举报
回复

取值的范围不同:

int16:-32768 到 32767

int32:-2,147,483,648 到 2,147,483,647


using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using Microsoft.VisualBasic; namespace ClockAlarm { public partial class Form1 : Form { public Form1() { InitializeComponent(); } [DllImport("kernel32", EntryPoint = "Beep")] public extern static int Beep(int dwfreq,int dwduration); public int intHour, intMouit, intSecon; private void Form1_Load(object sender, EventArgs e) { string strHour = DateTime.Now.TimeOfDay.Hours.ToString(); string strMouit = DateTime.Now.TimeOfDay.Minutes.ToString(); string strSecon = DateTime.Now.TimeOfDay.Seconds.ToString(); if (Convert.ToInt32(strHour) < 10) { strHour = "0" + strHour; } if (Convert.ToInt32(strMouit) < 10) { strMouit = "0" + strMouit; } if (Convert.ToInt32(strSecon) < 10) { strSecon = "0" + strSecon; } textBox2.Text = strHour + ":" + strMouit + ":" + strSecon; intHour= Convert.ToInt32(strHour); intMouit = Convert.ToInt32(strMouit); intSecon = Convert.ToInt32(strSecon); numericUpDown3.Value = Convert.ToInt32(strHour); numericUpDown2.Value = Convert.ToInt32(strMouit); numericUpDown1.Value = Convert.ToInt32(strSecon); } private void timer1_Tick(object sender, EventArgs e) { string strHour = DateTime.Now.TimeOfDay.Hours.ToString(); string strMouit = DateTime.Now.TimeOfDay.Minutes.ToString(); string strSecon = DateTime.Now.TimeOfDay.Seconds.ToString(); if (Convert.ToInt32(strHour) < 10) { strHour = "0" + strHour; } if (Convert.ToInt32(strMouit) < 10) { strMouit = "0" + strMouit; } if (Convert.ToInt32(strSecon) < 10) { strSecon = "0" + strSecon; } textBox1.Text = strHour + ":" + strMouit + ":" + strSecon; }

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧