Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP inlist() in c#
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01320903
Message ID:
01321015
Views:
49
>Here is how the VFP toolkit for .NET did it:
>
>/// <summary>
>/// Receives an expression and a list of values as parameter and returns a true
>/// if the expression exists in the list. Please note that the Visual FoxPro's
>/// InList() function has a limitation of in items whereas this one does not have
>/// a limitation on the number of items passed.
>/// </summary>
>/// <example>
>/// Console.WriteLine(InList("Kamal", "Pat", "abc", "Kamal"));	//returns true
>/// Console.WriteLine(InList("Kamal", "Pat", "abc", "xyz"));	//returns false
>/// Console.WriteLine(InList(123, 12, 13, 16, 1717, 123));	//returns true
>/// </example>
>/// <param name="tcExpression"></param>
>/// <param name="toVar"></param>
>/// <returns></returns>
>public static bool InList(object toExpression, params object[] toItems)
>{
>	return Array.IndexOf(toItems,  toExpression) > -1;
>}
>
>
>>if there any similar vfp inlist() command in C#?
>>
>>
>>for eg.
>>
>>VFP Code:
>>
>>IF INLIST(postCode,'001','002','003')
>>...
>>ENDIF
>>
>>
>>
>>Thanks.
___

Einar,

execution times

(1) for strings, the object[] approach is about double as fast as the string[] approach
Why could that be ?
ildasm string[]
call       bool [System.Core]System.Linq.Enumerable::Contains<string>(class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0>, !!0)

ildasm object[]
call       bool [System.Core]System.Linq.Enumerable::Contains<object>(class [mscorlib]System.Collections.Generic.IEnumerable`1<!!0>,!!0)
(2) Here I am not surprised - with value types - taken int to test
int[] is about 1/5th faster than object[] - no boxing I take it
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform