Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Class named String
Message
De
11/11/2013 11:26:32
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01587660
Message ID:
01587759
Vues:
39
J'aime (1)
>>>Probably true - but an extension method gets round Dmitry's naming problem :-}
>>
>>
>>True - but will clutter up
>>
>How do you decide when to go with a new class and when to go with extension and does extension bring overhead comparing with the class?

> How do you decide when to go with a new class and when to go with extension

Personal taste

If it does a specific thing, I prefer a new class - probably with static methods
If not often used- I prefer a separate class

eg I have one called BitOperations. It can test, set, clear a bit. It can rotate

If it can be used by more than one type, and I find it useful, I go for extension methods

For example, I have extension methods that test for equality. Can be used with any type that Implements IEquatable< T >
eg: testing whether ranges of arrays contain the same


> does extension bring overhead comparing with the class?

I don't think so. An extension method can also be called in the 'normal' way
static  class Test
	{

		internal static void Go()
		{
			int one = 1, two = 2;

			bool b = one.IsEqual(two);


			bool x = Equality.IsEqual(one, two);  // same as above
		}
	}
	static class Equality
	{
		internal static  bool IsEqual<T>(this T one, T two) where T : IEquatable<T>
		{
			return one.Equals(two);
		}
	}
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform