Generics: constraints on nullable types?

Where T : class Your current constraint where T : Object says "anything which is or inherits from System. Object", which is: everything. All types, including Int32 and String, inherit from System.Object.So constraining on Object would do nothing Edit: as usual, Eric shines a light on this in a far more accurate way : in C# every type derives from object".

Not true! The way to correct this myth is to simply replace "derives from" with "is convertible to", and to ignore pointer types: every non-pointer type in C# is convertible to object.

Where T : class Your current constraint, where T : Object says "anything which is or inherits from System. Object", which is: everything. All types, including Int32 and String, inherit from System.Object.So constraining on Object would do nothing.

Edit: as usual, Eric shines a light on this in a far more accurate way: "in C# every type derives from object". Not true! The way to correct this myth is to simply replace "derives from" with "is convertible to", and to ignore pointer types: every non-pointer type in C# is convertible to object.

I just tried it and it gives you the four object methods: GetType, GetHashCode, ToString and Equals. Bad day yesterday, bunch of stupid posts, sorry. – Yuriy Faktorovich Oct 10 '09 at 2:37 2 It's actually a myth that all types inherit from object: blogs.msdn.Com/ericlippert/archive/2009/08/06/… -- However, your point is well taken.

The reason we do not allow a constraint to object is because it is already the case that all type arguments must be convertible to object, so this is a constraint that means nothing, and is therefore probably an error. – Eric Lippert Oct 10 '09 at 21:20 This will not allow a nullable value type for T though, and he wants "anything that can be set to a null". – Pavel Minaev Oct 11 '09 at 2:13.

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