Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Naming conventions for custom methods?
Message
 
 
À
18/11/2008 02:54:49
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
01362229
Message ID:
01362525
Vues:
31
>> A method belongs to one and only one class, doesn't it?
>>
>
>Except, perhaps, when your are dealing with extension methods
>
>Here's one that applies to all classes
>
>
>public static partial class ExtensionMethods
>{
>        static public string MyToString<T>(this T s)
>	{
>		return "<" + s.ToString() + ">";
>	}
>		
>}
>
>
>or
>
>public static partial class ExtensionMethods
>{
>        static public string MyToString(this object s)
>	{
>		return "<" + s.ToString() + ">";
>	}
>		
>}
>
>
>
>Here's one that applies to all classes which implement IEquatable< T >
>
>
>public static partial class ExtensionMethods
>{
>     public static bool InList<T>(this T s, params T[] list) where T : IEquatable<T>
>		{
>			return list.Contains(s);
>		}		
>}
>
Thanks. Extension methods are still over my head at this point. I kinda sorta understand generics and interfaces, but have not gotten to extension methods. Yet ;-)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform