Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP inlist() in c#
Message
De
02/06/2008 09:02:42
 
 
À
02/06/2008 07:58:19
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01320903
Message ID:
01320941
Vues:
66
>>>>if there any similar vfp inlist() command in C#?
>>>>
>>>>
>>>>for eg.
>>>>
>>>>VFP Code:
>>>>
>>>>IF INLIST(postCode,'001','002','003')
>>>>...
>>>>ENDIF
>>>>
>>>>
>>>>
>>>>Thanks.
>>>
>>>As far as I know, there isn't. You can easily write one - and overload it for other types
>>>
>>>static bool Inlist(string s, params string[] list)
>>>{
>>>	for (int i = list.Length; --i >= 0; )
>>>		if (s.CompareTo(list[i]) == 0)
>>>			return true;
>>>	return false;
>>>}
>>>
>>
>>Not really a replacement for INLIST() but if you're passing an array as a parameter why not just use list.Contains(s) ?
>>Regards,
>>Viv
>
>_
>
>I'm not passing an array as a parameter - just receiving a variable number of parameters in an array;
>
>static void doit()
>{
>	bool il = Inlist("001", "001", "002", "003");
>	Console.WriteLine("Inlist: " + il);
>}
>static bool Inlist(string s, params string[] list)
>{
>	return list.Contains(s);
>}
>
>But you're right, Contains() is less code
bool il = Inlist("001", "001", "002", "003");
Neat!. I'd forgotten you could use that to create the array....
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform