Implementing Nullable Types in Generic Interface?

Nullable is not a class so you need to specify struct.

Nullable is not a class so you need to specify struct. Public interface IOurTemplate where T : class where U : struct { IEnumerable List(); T Get(U id); } This is the meta definition. Public struct Nullable where T : struct EDIT I wouldn't really do this but its probably the only way to get it to work.

Public class MyWrapperClass where T : struct { public Nullable Item { get; set; } } public class MyClass where T : class { }.

(embarrased) - thx for pointing out my oversight. :) – Jason N. Gaylord Aug 28 '09 at 3:42 This is not true.

That's why you can't have Nullable>. See my answer. – Mehrdad Afshari Aug 28 '09 at 3:45 Well this is what you get for not testing.

– ChaosPandion Aug 28 '09 at 3:52 By you I meant me. Kind of embarrassed here. – ChaosPandion Aug 28 '09 at 3:53 Don't be.

Actually at first, I didn't read the question completely. I just saw Int32 being used as a nullable type and freaked out and wrote an answer w/o reading completely. Had to delete and post the correct one.

– Mehrdad Afshari Aug 28 '09 at 3:55.

Nullable types don't satisfy class or struct constraints: C# Language Specification v3.0 (Section §10.1.5: Type parameter constraints): The reference type constraint specifies that a type argument used for the type parameter must be a reference type. All class types, interface types, delegate types, array types, and type parameters known to be a reference type (as defined below) satisfy this constraint. The value type constraint specifies that a type argument used for the type parameter must be a non-nullable value type.

All non-nullable struct types, enum types, and type parameters having the value type constraint satisfy this constraint. Note that although classified as a value type, a nullable type (§4.1.10) does not satisfy the value type constraint. A type parameter having the value type constraint cannot also have the constructor-constraint.

– Jason N. Gaylord Aug 28 '09 at 15:19 If you don't need constraints, remove them. If you want to use nullable types only, add a value type constraint (where T:struct) and use T?

In the class definition. – Mehrdad Afshari Aug 28 '09 at 15:56.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions