Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How To Overload This Method
Message
From
13/04/2009 03:43:50
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01394418
Message ID:
01394498
Views:
30
>>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
Previous
Reply
Map
View

Click here to load this message in the networking platform