Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP inlist() in c#
Message
De
01/10/2008 16:32:36
 
 
À
30/09/2008 05:36:26
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01320903
Message ID:
01352114
Vues:
57
Cool.
I can't actually remember what we were trying to do but I like the way you did it !

But I guess that since extension methods are, under the hood, built as regular methods then generics should work in the same way.

Best,
Viv.


>It's a bit late - I know - but I came across Extension methods yesterday - and generics work
>http://msdn.microsoft.com/en-us/library/bb383977.aspx
>
>
>
>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();
>
>	}
>
>}
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform