Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP inlist() in c#
Message
 
 
À
25/01/2013 13:29:39
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01320903
Message ID:
01564092
Vues:
41
>>>>If I try
>>>>
>>>>Int16 closeDrawers = 2;
>>>>
>>>>if (closeDrawers.InList(2,4))
>>>>
>>>>
>>>>
>>>>I get an error about Short don't have InList implemented. I bypassed it by using Int32 instead but just wondering what was wrong in the above.
>>>
>>>Remind us how you are currently implementing InList() ....
>>
>>
>> public static bool InList<T>(this T s, params T[] list)
>>        {
>>            return list.Contains(s);
>>        }
>
>At first sight
>
>closeDrawers is an Int16
>
>The generic class above, for int 16 , will compile into
>>
>> public static bool InList (this Int16 s, params Int16[] list)
>>        {
>>            return list.Contains(s);
>>        }
>
>Which means it is expecting Int16 as parameters
>
>Either of following solutions - not tested
>
>(1) declare closeDrawers as Int
>
>(2) cast closeDrawers to Int
>
>if (((Int)closeDrawers).InList(2,4))
>
>
>(3) pass shorts to Inlist
>
>>>>if (closeDrawers.InList(  (int16)2,  (int16)4))
>
I picked up the simplest solution of declaring closeDrawers as Int32 (although in the database it's tinyint). I think C# "thinks" that 2 and 4 are Int32 constants and this is why I'm getting an error. I probably could use your solution #3 also. Wondering if that's important in any way?

Thanks.
If it's not broken, fix it until it is.


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

Click here to load this message in the networking platform