Is this possible?
E.g. I have the following code, this will result in a compile error.
void fill_array
for (int i= 0; ii < count; count++) {
if (typeof(T) == typeof(int)) array_out[i] = i % 2; else array_out[i] = (i % 2) == 1;
// results in cannot cast int to T, and cannot cast bool to T.
}
return
;}
AlanPosted Jun 14, 2007, 2:23 PM
If I were you, I'd just code two non-generic overloads of the fill_array method, one that takes an int[] and the other a bool[] as its second parameter.
Incidentally, I assume you're wanting to allow for partial filling of the array, otherwise you could use array_out.Length instead of passing the 'count' parameter.