F
Fredo
I'm new to Generics (years and years of VS.NET 2003 development, but very
little .NET 2.0+). I have some routines for conversion from RGB to different
color spaces and back. I would like the routines to support, at least, byte,
int, and double types without having to create different versions of the
routines. Is there any way to do this with generics?
The problem is, if I do something like this:
public static void RGB_to_YIQ<T>(T[] R, T[] G, T[] B, T[] Y, T[] I, T[] Q)
{
Y[index] = 0.299 * R[index] + 0.587 * G[index] + 0.114 * B[index];
...
}
I get an error: "Operator '*' cannot be applied to operands of type 'double'
and 'T'"
Like I said, I'm a newb to the whole generics thing. I read the "Constraints
on Type Parameters" stuff using "where" in MSDN, but I'm not sure how I can
use that, if I can.
Thanks.
little .NET 2.0+). I have some routines for conversion from RGB to different
color spaces and back. I would like the routines to support, at least, byte,
int, and double types without having to create different versions of the
routines. Is there any way to do this with generics?
The problem is, if I do something like this:
public static void RGB_to_YIQ<T>(T[] R, T[] G, T[] B, T[] Y, T[] I, T[] Q)
{
Y[index] = 0.299 * R[index] + 0.587 * G[index] + 0.114 * B[index];
...
}
I get an error: "Operator '*' cannot be applied to operands of type 'double'
and 'T'"
Like I said, I'm a newb to the whole generics thing. I read the "Constraints
on Type Parameters" stuff using "where" in MSDN, but I'm not sure how I can
use that, if I can.
Thanks.