casting from System._ComObject
-
Hi All I have just a basic doubt regarding using objects of type
System._ComObject
. Once I know the underlying type, in oder to retrieve the right type of class, is it always correct to use the as keyword like this?// myComObject variable is of type System._ComObject
MyConcreteClassType o = myComObject as MyConcreteClassType;
if ( o != null )
{
// you can use MyConcreteClassTyp methods
} -
Hi All I have just a basic doubt regarding using objects of type
System._ComObject
. Once I know the underlying type, in oder to retrieve the right type of class, is it always correct to use the as keyword like this?// myComObject variable is of type System._ComObject
MyConcreteClassType o = myComObject as MyConcreteClassType;
if ( o != null )
{
// you can use MyConcreteClassTyp methods
}Don't post the same question in two places - it duplicates work and annoys people. I have deleted the Q & A version.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
Don't post the same question in two places - it duplicates work and annoys people. I have deleted the Q & A version.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
Hi All I have just a basic doubt regarding using objects of type
System._ComObject
. Once I know the underlying type, in oder to retrieve the right type of class, is it always correct to use the as keyword like this?// myComObject variable is of type System._ComObject
MyConcreteClassType o = myComObject as MyConcreteClassType;
if ( o != null )
{
// you can use MyConcreteClassTyp methods
}Not sure about the "always", but yes it is safe. Thc interop engine does the marshalling for you by implementing the appropriate type conversion. You can do it manually using th Marshal-utility.