摘要:The standard dispose idiom frees your unmanaged resorces using the IDisposable interface when clients remember,and it uses the finalizer defensively when clients forget.所以要为你的类添加 析构函数 以及 实现IDispose接口。...
阅读全文
随笔分类 - Effective C#的读书笔记
摘要:The standard dispose idiom frees your unmanaged resorces using the IDisposable interface when clients remember,and it uses the finalizer defensively when clients forget.所以要为你的类添加 析构函数 以及 实现IDispose接口。...
阅读全文
摘要:作者在这个Item的最后一段很好总结了,关于垃圾最少化的技术。摘如: The Garbage Collector does an efficient job of managing the momory that your application uses.But remember that creating and destroying heap object still takes tim...
阅读全文
摘要:这个Item没什么特别的,只是鼓励大家是用Conditinal Attributes,不要再是用c++风格的预定义语句
阅读全文
摘要:这个Item鼓励大家多是用is/as,除非的在不得已的情况下才是用原始的强制的类型转换值得注意的地方:as / is:作类型转换时,是检查其转换对象的runtime-type,它不会执行任何用户自定的操作。在转换时其runtime-type必须与目标类型相同,或是其继承自目标类型。as:不能用于value type,因为任何value type不能为null,而当as失败时返回nullcast:做...
阅读全文
摘要:这个Item主要讲作为常量的两种形式(readonly和const)的区别。 const 是编译时常量,指在编译时直接把这个静态常量直接替换成相应的数值 readonly 是运行时常量,指编译时任然是静态常量,在运行时才把它替换成相应的数值 如果你使用了一个DLL中的常量对象,他是用const声明的,当DLL中的那个常量发生改变的时候,如果你不重新编译你的应用程序,你的应用程序中是...
阅读全文
摘要:这个Item主要鼓励大家使用Properties。值得注意的地方: public interface INameValuePair{ object Value { get; set; }}public interface IConstNameValuePair{ object Name { get; } object Value { get; }}pub...
阅读全文
摘要:Types that use unmanaged system resource should be explicity released using the dispose() method of the IDisposable interface.这个Item只是建议多使用using和try...catch块。值得注意的是using语句本身也是将代码生成为try...catch块。他们产...
阅读全文
摘要:static variable storage is set to static variable initializers execute static constructor for the base class execute the static constructor execute instance variable storage is set to 0 in...
阅读全文
摘要:由于C#不知参数的默认值,but constructor initializers allow one constructor to call another construcor.所以经常出现一下这种形式的代码: public class MyClass{ private ArrayList _col; private string _name; public MyClass():t...
阅读全文
摘要:You know you should initialize static member variables in a type before you create ant instatnces of that type. C# let you use static initializers and a static constructor for this purpose. A stat...
阅读全文
摘要:编译器总是在运行Constructor前,先初始化成员变量(不包括静态变量)。当有初始化语句时,你不需要为每个构造函数添加初始化语句。Equally important,the initializers are added to the complier-generated default constructor.The C# complier creates a default construc...
阅读全文
摘要:摘录:The Garbage Collector(GC) controls managed memory for you.But the GC is not magic.You need to clean up after yourself,too.You are response for unmanaged resource such as file handles,database conne...
阅读全文
|