摘要:Build low-level data storage types as value types. Build the behavior ofyour application using reference types. You get the safety of copying datathat gets exported from your class objects. You get the memory usage benefitsthat come with stack-based and inline value storage, and you can utilizestand
阅读全文
摘要:The implementation of your IDisposable.Dispose() method is responsiblefor four tasks: 1. Freeing all unmanaged resources. 2. Freeing all managed resources (this includes unhooking events). 3. Setting a state flag to indicate that the object has been disposed. Youneed to check this state and throw
阅读全文
摘要:Here is theorder of operations for constructing the first instance of a type: 1. Static variable storage is set to 0. 2. Static variable initializers execute. 3. Static constructors for the base class execute. 4. The static constructor executes. 5. Instance variable storage is set to 0. 6. Ins
阅读全文
摘要:In some ways, resource management can be more difficult in C# than itwas in C++. You can’t rely on deterministic finalization to clean up everyresource you use. But a garbage-collected environment really is much simplerfor you. The vast majority of the types you make use of do not implementIDisposab
阅读全文
摘要:Many objects in the Cocoa framework are extended in much the same way. That is, there is an existing object that needs to be extended for your purpose. Instead of subclassing the table view, you simply supply it with a helper object. For example, when a table view is about to display itself, it
阅读全文
摘要:Static initializers and static constructors provide the cleanest, clearest wayto initialize static members of your class. They are easy to read and easy toget correct. They were added to the language to specifically address thedifficulties involved with initializing static members in other languages
阅读全文
摘要:Member initializers are the simplest way to ensure that the member variablesin your type are initialized regardless of which constructor is called.The initializers are executed before each constructor you make for yourtype. Using this syntax means that you cannot forget to add the properinitializati
阅读全文
摘要:In XSLT 2.0, xsl:value-of has a separator attribute. If the select attribute is a sequenceof items, those items are output in sequence, with the value of the separatorattribute between them. There are some changes to the xsl:number element in XSLT 2.0. First of all, three newformats have been a
阅读全文
摘要:Remember that translating your C# code into machine-executable code isa two-step process. The C# compiler generates IL that gets delivered inassemblies. The JIT compiler generates machine code for each method (orgroup of methods, when inlining is involved), as needed. Small functionsmake it much eas
阅读全文
摘要:Therefore, adding parameters, even if they are optional parameters, is abreaking change at runtime. If they have default values, it’s not a breakingchange at compile time. Now, after that explanation, the guidance should be clearer. For your initialrelease, use optional and named parameters to crea
阅读全文
摘要:There are seven kinds of nodes in XPath: • The document node (one per document) • Element nodes • Attribute nodes • Text nodes • Comment nodes • Processing instruction nodes • Namespace nodes
阅读全文
摘要:Conversion operators introduce a form of substitutability that causes problems in your code. You’re indicating that, in all cases, users can reasonably expect that another class can be used in place of the one you created. When this substituted object is accessed, you cause clients to work with temp
阅读全文
摘要:C# began as an imperative language. It continues to include all the featuresthat are part of that heritage. It’s natural to reach for the most familiartools at your disposal. However, those tools might not be the best tools.When you find yourself writing any form of a looping construct, ask yourself
阅读全文
摘要:Summarizing the default behavior, Object.GetHashCode() works correctlyfor reference types, although it does not necessarily generate an efficientdistribution. (If you have overridden Object.operator==(), you can breakGetHashCode()). ValueType.GetHashCode() works only if the first field inyour struct
阅读全文
摘要:[代码][代码]java -cp saxon9he.jar net.sf.saxon.Transform -t -greeting.xml -xsl:greeting.xsl -o:output.html[代码]
阅读全文
摘要:C# gives you numerous ways to test equality, but you need to consider providingyour own definitions for only two of them, along with supporting theanalogous interfaces. You never override the static Object.ReferenceEquals()and static Object.Equals() because they provide the correct tests, regardless
阅读全文
摘要:AppController.hCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--1#importFoundation/Foundation.h234@interfaceAppController:NSObject5{6IBOutletNSTextField*textField;7NSSpeechSynthesizer*speechSynth;8}910-(IBAction)sayIt:(id)sender;11-(IBAction)stopIt:
阅读全文
摘要:JavaScript ’ s lack of block - level scopes is a common source of confusion.[代码] When a variable is declared using var , it is automatically added to the most immediate contextavailable. In a function, the most immediate one is the function ’ s local context; in a with statement, themost immediate
阅读全文
摘要:The end result was forECMAScript to provide two sets of operators: equal and not equal to perform conversion beforecomparison, and identically equal and not identically equal to perform comparison without conversion.equalityCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.C
阅读全文
摘要:The Conditional attribute generates more efficient IL than #if/#endifdoes. It also has the advantage of being applicable only at the functionlevel, which forces you to better structure your conditional code. The compileruses the Conditional attribute to help you avoid the common errorswe have all ma
阅读全文
摘要:Remember that user-defined conversion operators operate only on thecompile-time type of an object, not on the runtime type. Now that you know to use as when possible, let’s discuss when you can’tuse it. The as operator does not work on value types. The is operator should be used only when you cann
阅读全文
摘要:2011年已经过去一周,月底就要回家过年了,定下计划先. 这次不能像之前那样计划定得太粗,完全没有东西可以准确衡量完成度. 1. 随笔达到600篇,这样算来,每月必须写25篇左右.一年下来,应该会看完至少20本书了. 2. C++, Python, Java应该都算入门了,希望在这一年里能更进一步 3. C++之前囫囵吞枣的看了好多书,但现在想想应该更深入地看一次. Thinking in C++(60%) Effective C++/More Effetive C++ The C++ Standard Libray Windows via C/C++ 研究开源项目Mongo
阅读全文
摘要:codeCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->1#include<iostream>2#include<vector>3#include<iterator>4usingnamespacestd;56template<classCont,classPtrMemFun>7voidapply(Cont&c,PtrMemFunf)8{9typenameCont::iteratorit=
阅读全文
摘要:Compile-time constants are limited to numbers and strings. Read-onlyvalues are also constants, in that they cannot be modified after the constructorhas executed. You can use readonly values for instance constants, storing different valuesfor each instance of a class type. Compile-time constants are
阅读全文
摘要:You can specify different accessibility modifiers to the getand set accessors in a property in C#. Indexers can be virtual or abstract; indexerscan have separate access restrictions for setters and getters. You cannotcreate implicit indexers as you can with properties.[代码]
阅读全文
摘要:If you are using the garbage collector, it is important that you not keep references to objects that you don't care about. In the main function of lottery, you should set the now and array pointers to nil when you lose interest in them.[代码] Objects are added to the current autorelease pool when t
阅读全文
摘要:For pages that require a lot ofJavaScript code, this can cause a noticeable delay in page rendering, during which time the browser willbe completely blank. For this reason, modern web applications typically include all JavaScript referencesin the body element, after the page content. HTML 4.01 de
阅读全文