摘要: 《大话设计模式》书中的方法 public partial class Form1 : Form { private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { Form2.GetSingleForm2().Show(); } } public partial class Form2 : Form { private static Form2 _singleForm = null; ... 阅读全文
posted @ 2013-06-14 18:04 瓜王 阅读(153) 评论(0) 推荐(0)
摘要: 1、时间顺序:静态成员的初始化=》非静态成员的初始化==》构造函数=》基类成员初始化=》基类构造函数2、因为静态成员初始化是由CLR调用的,如果出错,则程序会崩溃。所以,常常使用构造函数来初始化静态成员。static MySingleton( ){ try { _theOneAndOnly = new MySingleton( ); } catch { // Attempt recovery here. }}3、一段好的测试代码,测试对静态成员初始化的理解。class A{ public static int X = B.Y; static A() { ++X; }}cl... 阅读全文
posted @ 2013-06-14 15:36 瓜王 阅读(149) 评论(0) 推荐(0)
摘要: 原则十六:不要创建无效的对象。总结起来3点:1、创建和销毁堆对象仍然需要消耗时间。如protected override void OnPaint( PaintEventArgs e ){ // Bad. Created the same font every paint event. using ( Font MyFont = new Font( "Arial", 10.0f )) { e.Graphics.DrawString( DateTime.Now.ToString(), MyFont, Brushes.Black, new PointF( 0,0 )); }.. 阅读全文
posted @ 2013-06-14 15:05 瓜王 阅读(123) 评论(0) 推荐(0)