1、输出
1 2 3 4 5
| Console.WriteLine("输出");
Console.WriteLine(格式字符串(含替代标记),替换值0,替换值1,替换值2,...); Console.WriteLine("两个整数示例是 {0} 和 {1}",3,6);
|
2、计时
1 2 3 4 5
| DateTime beforeDT = System.DateTime.Now; 程序段 DateTime afterDT = System.DateTime.Now; TimeSpan ts = afterDT.Subtract(beforeDT); Console.WriteLine("DateTime costed for Shuffle function is: {0}ms", ts.TotalMilliseconds);
|
3、多线程
3.1 创建并启动线程
1 2
| Thread socketLine = new Thread(Recieve_Message); socketLine.Start();
|
3.2 线程信号量
1 2 3 4 5 6
| private readonly ManualResetEvent mresend = new ManualResetEvent(false);
mresend.WaitOne(); mresend.ReleaseMute(); mresend.Set(); mresend.Reset();
|
4、定时
4.1 定时器控件
定义在System.Windows.Forms里,占用主线程执行定时器功能
1 2 3
| timer.Interval = 1500; timer.Enabled = true;
|
4.2 定时器类
定义在System.Timers.Timer类里,不占用主线程。
1 2 3 4 5 6 7
| System.Timers.Timer t = new System.Timers.Timer(1000);
t.Elapsed += new System.Timers.ElapsedEventHandler(theout); t.AutoReset = true; t.Enabled = true;
|
5、文件
1 2 3 4 5 6 7
| string path = System.AppDomain.CurrentDomain.BaseDirectory + "parameter.txt"; File.Exists(@path) File.Create(@path) FileStream fs = new FileStream(path, FileMode.Open); fs.Seek(x, SeekOrigin.Begin); fs.Write(data, 0, data.Length); fs.Close();
|
6、绘图
1 2 3 4 5
| private Graphics g = this.panel1.CreateGraphics(); Pen p1 = new Pen(Color.Yellow, 0.2f); g.Clear(Color.White); g.DrawLine(p1, new PointF(x1, y2), new PointF(x2, y2)); g.DrawEllipse(p1, x, y, w, h);
|