Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Handling DB Nulls
Message
 
 
À
29/12/2009 11:51:32
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01440804
Message ID:
01441061
Vues:
24
>>>>>The WHERE restricts the classes it applies to.
>>>>>
>>>>>See possible clauses : http://msdn.microsoft.com/en-us/library/d5x73970.aspx
>>>>>They can be combined - it's an AND combination
>>>>>
>>>>>If you want to use eg between/max, .., you want the type to implement IComparable(T)
>>>>>
>>>>>public static bool Between<T>(this T s, T s1, T s2) where T : IComparable<T>
>>>>>
>>>>>public static T Max<T>(params T[] array) where T : IComparable<T>
>>>>>
>>>>>
>>>>>
>>>>>For an InList you'll need IEquatable(T)
>>>>>
>>>>>public static bool InList<T>(this T s, params T[] array) where T : IEquatable<T>
>>>>>		{
>>>>>			return array.Contains(s);
>>>>>		}
>>>>>
>>>>
>>>>Gregory,
>>>>
>>>>Thanks a lot.
>>>>
>>>>Now I don't understand this
>>>>
>>>>public static T GetNonNull<T>(this  T? value) where T : struct
>>>>		{
>>>>			return value == null ? default(T) : (T)value;
>>>>		}
>>>>
>>>>It says that it could be any value type except for Nullable types. But paramter of the method is Nullable type. Can you explain it then?
>>>>
>>>>Thanks a lot again.
>>>
>>>
>>>I think it says that T must be a value type. The T? says it accepts the nullable version of the value type
>>
>>I think there is some contradiction I still don't understand. From the link:
>>
>>where T: struct
>> The type argument must be a value type. Any value type except Nullable can be specified. See Using Nullable Types (C# Programming Guide) for more information.
>
>probably means we cannot write
>
>where T?: struct
>
>
>
>>and then we're using nullable value type for the parameter. Why does it work?
>
>
>We still pass T - except it is nullable

Why for inlist we need to use IEquatable(T) and not IComparable ?
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform