>using System; >using System.Collections.Generic; > >class myInList >{ > static void Main() > { > DateTime t = DateTime.Now; > string[] myStringList = {"john","frank","michel"}; > int[] myIntList = {4,5,12,23}; > DateTime[] myDateTimes = { t, t.AddDays(1), t.AddDays(-1)}; > Console.WriteLine("{0} is inlist: {1}", "michel",InList<string>( "michel", myStringList ) ) ; > Console.WriteLine("{0} is inlist: {1}", "cetin", InList<string>( "cetin", myStringList ) ) ; > > Console.WriteLine("{0} is inlist: {1}", 5, InList<int>( 5, myIntList ) ) ; > Console.WriteLine("{0} is inlist: {1}", 1, InList<int>( 1, myIntList ) ) ; > > Console.WriteLine("{0} is inlist: {1}", t, InList<DateTime>( t, myDateTimes ) ) ; > Console.WriteLine("{0} is inlist: {1}", t.AddDays(1), InList<DateTime>( t.AddDays(1), myDateTimes ) ) ; > Console.WriteLine("{0} is inlist: {1}", t.AddDays(2), InList<DateTime>( t.AddDays(2), myDateTimes ) ) ; > > } > public static bool InList<T>(T searchFor, T[] searchInList) where T : IComparable<T> > { > return ( Array.IndexOf(searchInList,searchFor) != -1 ); > } >} >Thanks, this is really good. Here is the conversion:
' VFP inlist equivalent ' expO1 Item where all the items will be tried to look into ' expO2 Param array for a list of items Public Function Inlist(ByVal toItem As IComparable, ByVal ParamArray toItems() As IComparable) As Boolean Return Array.IndexOf(toItems, toItem) <> -1 End Function