Casting
§VB.NET
§Explicit casting – CType (expression,  type )
§
§Dim blkRef As BlockReference
§blkRef = CType(ent, BlockReference)
§
§In C#
§Line myLine = (Line)myObject;
§‘as’ operator - if it fails, no exception, but object gets set to null!
Line myLine = myObject as Line;
§‘is’ operator – if  (myObj is Line) …
§
The .NET API allows you to cast an object from one type to another. This is necessary when iterating objects in a collection that has multiple types and you only want to work with a certain type in that collection. For examplethrough the modelspace blockTableRecord and you want to do something only with the BlockReferences. The code would test to see if the type of entity is a BlockReference  lets say the code is iterating and if it is, it would cast that entity to a BlockReference. In Visual Basic casting is done using the Ctype function. Notice that this function takes the object for the first argument, and a type for the second argument.  In C# you use the Type in parentheses to cast the entity to the object on the left side of the equals sign. You can also use the as operator and then test to make sure the object is not null. The is operator can also be helpful to test the type of the object.