Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP inlist() in c#
Message
From
30/09/2008 06:19:05
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01320903
Message ID:
01351726
Views:
49
>When I try to compile the code I get a slew of errors such as the ones below
>
>
>Error	1	'int' does not contain a definition for 'InList'
>Error	2	'string' does not contain a definition for 'InList'	
>Error	3	'System.Array' does not contain a definition for 'Contains'	
>
>
>
>have you compiled it ? ( I'm using VS2005 )

Yes - I always compile

I'm using vs2008 - dunno about vs2005

Try this example: http://msdn.microsoft.com/en-us/library/bb311042.aspx

Here's the code again - in case I missed something
	public static class ExtensionMethods
	{
		public static bool InList<T>(this T s, params T[] list)
		{
			return list.Contains(s);
		}
	}

	class Test
	{

		static void Main(string[] args)
		{
			string s = "456";
			Console.WriteLine(" string {0}", "456".InList("123", "456"));
			Console.WriteLine(" string {0}", s.InList("123", "456"));

			int i = 4;
			Console.WriteLine(" int {0}", 5.InList(4, 5, 6));
			Console.WriteLine(" int {0}", 29.InList(4, 5, 6));
			Console.WriteLine(" int {0}", i.InList(4,5,6));

			Console.ReadLine();

		}


	}
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform