Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How To Overload This Method
Message
De
13/04/2009 03:43:50
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01394418
Message ID:
01394498
Vues:
33
>>I have a method call GetClients. It take either a CompanyKey, a ClientKey or both. Both of them are int's.
>>
>>
>>        public static SqlDataReader GetClients()
>>        {
>>            return GetClients(-1, -1);
>>        }
>>        public static SqlDataReader GetClients(int iClientKey)
>>        {
>>            return GetClients(-1, iClientKey);
>>        }
>>        public static SqlDataReader GetClients(int iCompanyKey)
>>        {
>>            return GetClients(iCompanyKey, -1);
>>        }
>>        public static SqlDataReader GetClients(int iCompanyKey, int iClientKey)
>>        {
>>           // The code is here
>>        }
>>
>>
>>I get a compile error on the third overload "csAppDataAccess' already defines a member called 'GetClients' with the same parameter types"
>>
>>Even though the paramaters are both the same type, they represent different data. I guess I could make one a double and the other int, but I'm wondering if there's a better way?
>
>You're right, in order to overload a method the parameter types have to be different. How about two methods, GetClientsByClient() and GetClientsByCompany()?

Or GetClient() and GetClientsByCompany90 ?
Or wait for C# 4 where we get named parameters :-}
Viv
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform