So it turns out it's not a limitation of generics after all!, it's simply
a limitation of my understanding of generics. ;-)
Thank you for the explanation, it does make sense, and thank you as well for
the suggestion about how to go about solving my problem.
Regards,
Yago Alvarado
On Fri, 17 Mar 2006 17:03:08 +0100, Ryan Heath <[EMAIL PROTECTED]> wrote:
>Types List<Country> and List<IObjectFinder> are distinct types.
>
>I think you want something like
>
>public int GetObjectIndexByID<T>(List<T> myList, int objectID) where T
>: IObjectFinder
>
>Now you are saying that the types the List holds must be derived from
>IObjectFinder.
>
>HTH
>// Ryan
>
>On 3/17/06, Alvarado, Yago <[EMAIL PROTECTED]> wrote:
>> Hi everyone,
>>
>>
>> I am having a problem when using a List<T> collection and I'm not
>> quite sure whether I just hit a limitation of generics in .NET 2.0 or
>> whether I'm simply doing something wrong.
>>
>>
>> I've defined an interface like below:
>>
>>
>> public interface IObjectFinder
>> {
>> int ObjectID
>> { get;}
>> }
>>
>>
>> And then I've got several objects (like Country, Contact, etc...)
>> implementing this interface.
>>
>> I've also created the following method as below:
>>
>> public int GetObjectIndexByID(List<IObjectFinder> myList, int objectID)
>> {...}
>>
>>
>> When I try to use this method from my class
>>
>> List<Country> myCountryList = GetCountryList();
>>
>> int index = GetObjectIndexByID(myCountryList,5);
>>
>>
>> I get the following errors:
>>
>> The best overloaded method match for
>> 'GetObjectIndexByID(System.Collections.Generic.List<IHPObjectFinder>,
>> int)' has some invalid arguments.
>> Cannot convert from 'System.Collections.Generic.List<Country>' to
>> 'System.Collections.Generic.List<IHPObjectFinder>'
>>
>> As I mentioned above, the Country object implements the IObjectFinder
>> interface.
>>
>> Am I missing something here or is this a bug/limitation with generics?
>>
>>
>> Regards,
>> Yago
>>
>>
>>
>> - -----------
>> Marketing Magazine's Contact Centre Agency of the Year 2005
>> Field Marketing Gold - DMA / Royal Mail Awards
>> Best Overall Site - British Gas Outbound Sales Awards
>>
>> http://www.cpm-int.com
>> - -----------
>>
>> _____________________________________________________________________
>> This e-mail is confidential and is intended solely for the use of the
individual or entity to whom it is addressed. If you are not the intended
recipient and you have received this e-mail in error then any use,
dissemination, forwarding, printing or copying of this e-mail is strictly
prohibited. You should contact the sender by return e-mail and delete and
destroy all the information from your system. Any views or opinions
presented are solely those of the author and do not necessarily represent
those of CPM. This email does not form part of a legally binding agreement.
We have taken precautions to minimise the risk of transmitting software
viruses or trojans, but we advise that you carry out your own virus checks
on any attachments to this message. We cannot accept liability for any loss
or damage caused to your software, hardware or system.
>>
>> Please note that all messages sent to CPM are actively monitored for
inappropriate material and/ or content.
>>
>> ===================================
>> This list is hosted by DevelopMentor(r) http://www.develop.com
>>
>> View archives and manage your subscription(s) at http://discuss.develop.com
>>
>
>===================================
>This list is hosted by DevelopMentorĀ® http://www.develop.com
>
>View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentorĀ® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com