Question regarding generics and type constraints
- From: "Fredo" <fredo@xxxxxxxxxxx>
- Date: Wed, 13 Feb 2008 10:15:49 -0600
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.
.
- Follow-Ups:
- Re: Question regarding generics and type constraints
- From: Rene
- Re: Question regarding generics and type constraints
- From: Marc Gravell
- Re: Question regarding generics and type constraints
- Prev by Date: Re: I'd appreciate your opinion(s)
- Next by Date: Re: Question regarding generics and type constraints
- Previous by thread: Xbap + database
- Next by thread: Re: Question regarding generics and type constraints
- Index(es):
Relevant Pages
|