摘要: 说的是C#如何体贴程序员,而非.NET Framework。这是C#对Dispose调用下的细微功夫: using(var obj= new MyClass( )) { obj.SomeMethod( ); }上面的代码等价于下面的,如何,C#体贴不? MyClass obj = new MyClass( ); try { obj.SomeMethod( ); } finally { if(obj != null) { IDisposable disposable = obj; disposable.Dispose( ); } }(按:code source from<<Progr 阅读全文
posted @ 2011-10-20 08:50 James Leng 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 说的是C#如何体贴程序员,而非.NET Framework。这是C#对Monitor使用下的细微功夫: MyClass obj; //Some code to initialize obj; lock(obj) { obj.DoSomething( ); }上面的代码等价于下面的,如何,C#体贴不? MyClass obj; //Some code to initialize obj; Monitor.Enter(obj); try { obj.DoSomething( ); } finally { Monitor.Exit(obj); }(按:code source from<< 阅读全文
posted @ 2011-10-20 08:50 James Leng 阅读(241) 评论(0) 推荐(1) 编辑
摘要: 说的是C#如何体贴程序员,而非.NET Framework。这是C#对Finalizer下的细微功夫: public class MyClass { public MyClass( ) {} ~MyClass( ) { //Your destructor code goes here } }上面的代码等价于下面的,如何,C#体贴不? public class MyClass { public MyClass( ) {} protected virtual void Finalize( ) { try { //Your destructor code goes here } finally .. 阅读全文
posted @ 2011-10-20 08:49 James Leng 阅读(347) 评论(2) 推荐(1) 编辑