Re: can constraint generics using string or not ?
- From: "Tom Porterfield" <tpporter@xxxxxxxx>
- Date: Thu, 7 Dec 2006 14:09:23 -0500
SHEBERT wrote:
// CS0703: `string' is not a valid constraint. A constraint must be an
interface, a non-sealed class or a type parameter
public class C<T> where T : string
{
}
Why can't I constraint using string but I can constraint like bellow and
it accept string?
public class C<T>
{
}
except now T accept anything, and I would like string, in fact, what I
would like is this:
public class C<T> WHERE T : struct, string
{
}
I agree with Dustin, what's your point in doing this? Restricting a generic to be a type that is a sealed class removes your ability for it to be constructed from anything other than that sealed class, in this case string, so it's no longer generic.
Since this is not a valid use of generics, possibly you are trying to solve a problem for which there is a better way than generics. What is it you are trying to accomplish?
--
Tom Porterfield
.
- Follow-Ups:
- Re: can constraint generics using string or not ?
- From: SHEBERT
- Re: can constraint generics using string or not ?
- Prev by Date: Re: Storing a Form in a Hashtable
- Next by Date: Re: Using js file in asp.net 2.0
- Previous by thread: Re: can constraint generics using string or not ?
- Next by thread: Re: can constraint generics using string or not ?
- Index(es):
Relevant Pages
|