I can't extract string data from a type object

C

Chris

I am calling a COM object that returns a type Object and
it contains two strings but I can't get them out. Here is
the command:

object ParamNameObj= localxPCCOMOBJ.xPCTarget.GetParamName
(1);

ParamNameObj shows up as a System.Array in the watch window
with the following elements.
-[0] datastr1 as string
-[1] datastr2 as string

But I can't get the data. I've tried .ToString object
method and it gives me "System.Array" I've tried to
reference the object as an array but it tells me that the
object is variable and not a method.

Thanks,
Chris
 
J

Jon Skeet [C# MVP]

Chris said:
I am calling a COM object that returns a type Object and
it contains two strings but I can't get them out. Here is
the command:

object ParamNameObj= localxPCCOMOBJ.xPCTarget.GetParamName
(1);

ParamNameObj shows up as a System.Array in the watch window
with the following elements.
-[0] datastr1 as string
-[1] datastr2 as string

But I can't get the data. I've tried .ToString object
method and it gives me "System.Array" I've tried to
reference the object as an array but it tells me that the
object is variable and not a method.

Could you show *how* you've tried to use it as an array?
 
C

Chris

-----Original Message-----
Chris said:
I am calling a COM object that returns a type Object and
it contains two strings but I can't get them out. Here is
the command:

object ParamNameObj= localxPCCOMOBJ.xPCTarget.GetParamName
(1);

ParamNameObj shows up as a System.Array in the watch window
with the following elements.
-[0] datastr1 as string
-[1] datastr2 as string

But I can't get the data. I've tried .ToString object
method and it gives me "System.Array" I've tried to
reference the object as an array but it tells me that the
object is variable and not a method.

Could you show *how* you've tried to use it as an array?

--
Jon Skeet - <[email protected]>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.
I have tried:

string test=ParamNameObj[0];

error: 'ParamNameObj' denotes a 'variable' where
a 'method' was expected


I've tried:
string test=ParamNameObj(0);
(as seen in a VB examble using this COM object)

error: Cannot apply indexing with [] to an expression of
type 'object'

I've also tried a foreach loop:

foreach (string test in ParamNameObj)
{
}

error: foreach statement cannot operate on variables of
type 'object' because 'object' does not contain a
definition for 'GetEnumerator', or it is inaccessible
 
S

Sunny

Hi try this:

string[] myretvalues = (string[])ParamNameObj;

foreach (string test in myretvalues)...



Sunny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top