Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / July 2004

Tip: Looking for answers? Try searching our database.

Array.IList implementation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
A J Le Couteur Bisson - 15 Jul 2004 11:40 GMT
I am very confused with the Array.IList implementation.  All of the methods
are private which hardly seems to be fulfilling the IList contract...  If I
cast an array then IList methods (e.g. Contains()) work correctly for arrays
of rank 1.  Where is the code that check the rank of arrays and
allows/disallows IList.Contains() accordingly?  I am using Reflector to
examine the framework code and I cannot find this functionality. Any clues?

Thanks,
Andy
Mattias Sj?gren - 15 Jul 2004 13:26 GMT
>All of the methods
>are private which hardly seems to be fulfilling the IList contract...

Why not? Interfaces don't specify which accessibility the implementing
method must have - private is fine.

>If I
>cast an array then IList methods (e.g. Contains()) work correctly for arrays
>of rank 1.  Where is the code that check the rank of arrays and
>allows/disallows IList.Contains() accordingly?

Array::System.Collections.IList.Contains(object) calls
Array::IndexOf(Array, object), which in turn calls
Array::IndexOf(Array, object, int, int). There you'll find code that
checks the Rank and throws an exception if it's != 1.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

A J Le Couteur Bisson - 15 Jul 2004 14:15 GMT
> >All of the methods
> >are private which hardly seems to be fulfilling the IList contract...
>
> Why not? Interfaces don't specify which accessibility the implementing
> method must have - private is fine.

Thanks for the prompt response.  Clearly the contract offered by interfaces
*can* be rather less useful than I supposed.  (I am reminded of a past
employer
which, under contract to make 'a delivery', delivered an empty box!**)

I am still puzzled as to why these methods are private.  What harm could
result
from making them public?

if((myArray as IList).Contains(3))

doesn't seem any clearer or more appropriate than

if(myArray.Contains(3))

Thanks,
Andy

** A very large company that ought to know better...
Mattias Sj?gren - 20 Jul 2004 09:50 GMT
Andy,

>I am still puzzled as to why these methods are private.  What harm could
>result from making them public?

I don't know why they decided to implement IList privately. Perhaps
because the interface is only partially supported (the Add, Insert,
Remove and RemoveAt methods will throw).

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.