Re: generics - constraint
- From: "Jesse McGrew" <jmcgrew@xxxxxxxxx>
- Date: 13 Jan 2007 22:38:19 -0800
Michael Moreno wrote:
I am trying to write a generic class where the underlying type is
either an int, a float or a double:
public class CMatrix<T>: ICloneable where VarType: int, float, double
but that does not compile.
The error message is :
'int' is not a valid constraint. A type used as a constraint must be an
interface, a non-sealed class or a type parameter.
Is it possible to do what I want?
No, I think the best you can do is write a static constructor that
checks typeof(T) and throws an exception if it isn't int, float, or
double.
Jesse
.
- Follow-Ups:
- Re: generics - constraint
- From: Michael Moreno
- Re: generics - constraint
- References:
- generics - constraint
- From: Michael Moreno
- generics - constraint
- Prev by Date: Re: Boxing and Unboxing ??
- Next by Date: Re: generics - constraint
- Previous by thread: generics - constraint
- Next by thread: Re: generics - constraint
- Index(es):
Relevant Pages
|