A dev at Microsoft working on a large managed code base just suggested this guideline… Our perf team buys it as well..


is should only be used when it's only necessary to test the type of some object. If you're going to use the object if the is condition succeeds, use as instead. This prevents two cast operations which can be expensive. For instance:



          Foo foo = obj as Foo;  //only cast
          if (foo != null)


                    // use Foo




          if (obj is Foo)  // cast 1
                    Foo foo = (Foo)obj; //cast 2
                    // use foo…