ITSWITCH #1: Answer

Last post I detailed some code that may or may not have something wrong in it.  If you thought InitializeOne and IntializeTwo are semantically identical (e.g. they differ only by performance), you’d be wrong. If you simply ran the code, you’d be able to guess where the problem is.  To understand what’s causing the problem.  Let’s look at how C# effectively implements the two loops. InitializeOne is essentially equivalent to         private class PrivateDelegateHelper         {             public String Value { get; set; }             public void Method()             {                 TestClass.ProcessText(Value);             }         }           public void … Continue reading ITSWITCH #1: Answer


Is There Something Wrong In This Code Here UPDATE: as several readers pointed out there was compile error in the code what was being displayed.  The line “String value = string[i]” was showing up as “String value = string”.  I’m not sure why; but throwing some spaces between the i and the square brackets seems to have solved it. In the following class, is there something wrong with either InitializeOne or InitializeTwo (hint, it has nothing to do with compile errors and I’m ignoring performance differences)?     public class TestClass     {         private List<MethodInvoker> delegates;           private … Continue reading ITSWITCH: #1

Working with Resharper’s External Annotation XML Files

Resharper 4.0 has external annotation XML files that you can create to give Resharper more information about your code.  For example, you can tell Resharper that a particular method does not accept a null argument.  For example, the following method does not accept a null argument: using System;   namespace Utility {     public static class Text     {         public static int GetLength(String text)         {             if (text == null) throw new ArgumentNullException(“text”);             return text.Length;         }     } } An external annotation file can be created to inform Resharper … Continue reading Working with Resharper’s External Annotation XML Files

Drag-copying in Visual Studio Solution Explorer.

NOTE: I’ve tried this in Visual Studio 2008 (VS2k8), I’m assuming the same thing happens in Visual Studio 2005 (VS2k5). In the process of refactoring, it’s *very* common for me to rename a type.  This is most easily done by renaming the file in the Solution Explorer (SE)–which renames the file, the type, and and any uses of the type in the entire solution. Occasionally, I need to create a new type based on another.  Copying an abstract type in order to implement the abstract type is often handy–I just fill in the abstract members (and delete “abstract”) in the … Continue reading Drag-copying in Visual Studio Solution Explorer.

Multi-platform Testing

Sometimes in the testing of our code we need to ensure what we’ve written works in various environments.  Sometimes that’s pre-XP Windows, low-resolution computers, etc. One way is to have a group of computers on hand with various versions of Windows and configurations installed for testing.  Another is to have a series of virtual PCs on your computer that can be run.  Sometimes you can use your running version of Windows… There are compatiblity settings in XP and greater that allow you to tell Windows to ignore certain features when running an application. Windows XP and greater as a concept … Continue reading Multi-platform Testing

Nested Types

Recently Michael Features blogged about nested types.  The title was almost “nested types considered harmful”. I don’t agree.  I don’t agree that they’re any more harmful than any other C# construct (except goto…).  Nested types are like anything else in our tool-belt: they have a time and place and can be abused. But, when to use them?  Well, for the most part I agree with Michael, you should avoid them. But, there are times when they’re simply the best solution in a given set of circumstances. Let’s look at asynchronous programming model (APM) in .NET.         // Paraphrased from … Continue reading Nested Types