Type conversion/ costum_type[] to int[]

  • Thread starter Thread starter time_error
  • Start date Start date
T

time_error

Hi,
Environment: VS2005 standard, programming app/service for WinCE 5.0

I'm trying to use the Win32 DeviceIoControl(...) from C# with P/
Invoke.
In my managed C# code the inbuffer of DeviceIoControl is defined as
int[], but the data (type of buffer) I want to use is not. Actullay is
an array of a selv-defined class:

TPhonebook[] myPonebook = new TPhonebook[100];

The error description says: cannot convert from TPhonebook[]' to
'int[]'.

In C++ it is very easy to force a type conversion, but how is this
accomplished in C#?

Regards,
Jonas
 
Environment: VS2005 standard, programming app/service for WinCE 5.0

I'm trying to use the Win32 DeviceIoControl(...) from C# with P/
Invoke.
In my managed C# code the inbuffer of DeviceIoControl is defined as
int[], but the data (type of buffer) I want to use is not. Actullay is
an array of a selv-defined class:

TPhonebook[] myPonebook = new TPhonebook[100];

The error description says: cannot convert from TPhonebook[]' to
'int[]'.

In C++ it is very easy to force a type conversion, but how is this
accomplished in C#?

Have a look at Array.ConvertAll. Basically, you provide a converter
delegate which can convert a TPhoneBook into an int, and
Array.ConvertAll will produce a new int[] for you.
 
Jonas,

In C#, you are going to have to iterate through the array of
classes/structures and assign the values you want to a new integer array
instance.

Hope this helps.
 

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

Back
Top