1.1取时间差
时刻:DateTime 时差:TimeSpan
代码:
DateTime time1 = DateTime.Now; textBox1.Text = time1.ToString(); ; i < ; i++) ; j < ; j++) ; DateTime time2 = DateTime.Now; textBox2.Text = time2.ToString(); TimeSpan time = time2.Subtract(time1).Duration(); textBox3.Text = time.ToString();
1.2使用StopWatch计时
Stopwatch sp = new Stopwatch(); sp.Start(); ; i < ; i++) temp += i.ToString(); sp.Stop(); Console.WriteLine(sp.Elapsed.TotalMilliseconds.ToString());
2.窗体自动居中
,(Screen.Height-);
3.如何Ping一个IP地址
命名空间:
using System.Net.NetworkInformation;
Ping一个固定的IP地址:
string Address="100.73.56.192"; ;i<;i++) { Ping ping = new Ping(); PingReply reply = ping.Send(Address, ); Console.WriteLine("来自{0}的回复:状态:{1},时间:{2};", Address, reply.Status, reply.RoundtripTime); } Console.ReadLine();
4.计算字符串占用的空间大小
Size size = TextRenderer.MeasureText(text, this.Font);
5.Debug调试:Debug模式下才执行
#if DEBUG Console.WriteLine("调试中的debugNumber: "+debugNumber); #endif