Click here to Skip to main content
15,908,112 members

Comments by supercat9 (Top 5 by date)

supercat9 9-Dec-11 18:04pm View    
It may be useful to have a search method accept an IComparer and IEqualityComparer, and use those for searching, to allow for lists that are sorted with something other than the default comparison method for the type. The reason for having both IComparer and IEqualityComparer is that it is possible for items to be unranked and yet not be identical (e.g. one might be using case-insensitive string sorting rules, but want to find it a particular case-sensitive string exists in the list). A binary search would find an item that sorts identically to the item being sought; a linear search could then look for the actual item.
supercat9 29-Aug-11 17:51pm View    
KeepAlive can be required even in 100% managed code, if a component of an object may be used in circumstances where the compiler can tell that the object itself won't be needed any more. There are two main ways this can happen: (1) if the object overrides Finalize in such a way as to invalidate the object's components, the Finalize method may fire while those components are in use; (2) if a WeakReference exists to an object, that WeakReference might be valid before the object calls a method on one of its components, but become invalid during the execution of that method.
supercat9 27-May-11 11:47am View    
I don't like creating needless delegates; to my mind, simply creating a temporary variable is cleaner. I do wish there were a standard idiom for introducing a block purely for scoping purposes; "if(1)" seems a little icky, and blocks which don't control a conditional or looping construct often look like something's "missing". BTW, the "With" construct in VB can be used with value types in ways that would require multiple variables in C. For example, if Foo is an array of a value type, "With Foo(I,J)" will effectively latch the values of Foo, I, and J; I don't know if it avoids the recomputation of the array subscript for each access.
supercat9 18-Feb-11 12:29pm View    
Still evil, since "if (whatever) some_macro; else something_else;" won't work. The proper form is "#define some_macro() do {this; that; the_other;} while(0)" (with no trailing semicolon).
supercat9 25-Oct-10 12:10pm View    
It may also be good to mention the StringBuilder.AppendFormat method, which is useful when adding multiple things to a StringBuilder.