I was wondering if it's possible to use some sort of Array.Copy method in C# to copy elements of one array to and array of same size but different type.
I get a struct from a native c++ library that contains a pointer to Integer and a size element. These integer values represent enum Values from enum Foo
.
At the moment I'm using a for loop. Is there a better/safer approach?
Thanks!
Using Array.Copy
throws an ArrayTypeMismatchException
as shown below:
using System;
public class Program
{
public enum Foo
{
FOO_1,
FOO_2
}
public static void Main(string[] args)
{
int nCount = 1;
Foo[] fooArr = new Foo[nCount];
Int32[] RawData = new Int32[nCount];
RawData[0] = 100;
Array.Copy(RawData, fooArr, nCount);
}
}