472,975 Members | 1,682 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,975 software developers and data experts.

About Array and IList

Hello!

The Array class implements these interfaces IClonable, IList, ICollection
and IEnumerable.
Note only interfaces are inherited and no classes so these interfaces will
be implemented in the derived class.

In Interface IList have a couple of members that is not available from the
Array object.
For example if I do the following
int[] vector = new int[5];
And then use the intellisense on instance vector I can't see for example
Add, Remove RemoveAt
there are more but these are just example of members that are not available
from the vector instance.

So my question is how is this possible?
I must have missed something here about implementing interfaces !
I have always thought that all implemented members must be accessible from
the derived class which
is not the case in this example.

//Tony

Jun 29 '08 #1
2 4368
Tony Johansson wrote:
Hello!

The Array class implements these interfaces IClonable, IList, ICollection
and IEnumerable.
Note only interfaces are inherited and no classes so these interfaces will
be implemented in the derived class.

In Interface IList have a couple of members that is not available from the
Array object.
For example if I do the following
int[] vector = new int[5];
And then use the intellisense on instance vector I can't see for example
Add, Remove RemoveAt
there are more but these are just example of members that are not available
from the vector instance.

So my question is how is this possible?
I must have missed something here about implementing interfaces !
I have always thought that all implemented members must be accessible from
the derived class which
is not the case in this example.

//Tony
They are accessible from the class, but they are implemented explicitly,
which means that you need an IList reference to access them.

This compiles:

((IList)someArray).Add(42);

Of course it throws a NotSupportedException if you try to run the code.

--
Göran Andersson
_____
http://www.guffa.com
Jun 29 '08 #2
Tony Johansson wrote:
Hello!

The Array class implements these interfaces IClonable, IList, ICollection
and IEnumerable.
Note only interfaces are inherited and no classes so these interfaces will
be implemented in the derived class.

In Interface IList have a couple of members that is not available from the
Array object.
For example if I do the following
int[] vector = new int[5];
And then use the intellisense on instance vector I can't see for example
Add, Remove RemoveAt
there are more but these are just example of members that are not available
from the vector instance.

So my question is how is this possible?
You need to cast your Array to IList first:

string[] strings = new string[] { "foo", "bar" };
IList stringList = (IList)strings;
Console.WriteLine(stringList.Contains("foo"));

That is because IList is explicitly implemented by Array.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 29 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: HairlipDog58 | last post by:
I have a component that implements a property called obj of type object. The intent is that a user can pass in any value or array of values and I will be able to retrieve the values. If the...
4
by: emma middlebrook | last post by:
Hi Straight to the point - I don't understand why System.Array derives from IList (given the methods/properties actually on IList). When designing an interface you specify a contract. Deriving...
3
by: Chris | last post by:
Hi, the specs for System.Array are : public abstract class Array : ICloneable, IList, ICollection, IEnumerable but I can't use any of the functions presented by IList in my code ...
3
by: ad | last post by:
Hi, When I studied CSharp, I am confuse by IList, Collection and Array. What is the relationships between them?
4
by: Jim Shaffer | last post by:
Perhaps I have the wrong construct, or misunderstand arrays in vb (2003).... I've loaded a two-dimensional array (168 by 28) into memory as AcctArray. {Dim AcctArray (500,28) as string...} The...
4
by: kin | last post by:
After a I read Walkthrough: Connecting to Data in Objects (http://msdn2.microsoft.com/en-us/library/ms171892.aspx#Mtps_DropDownFilterText). I still have project on that. My School project...
7
by: Jim Lewis | last post by:
I'm trying to move a function into pyrex for speed. The python side needs to pass a list to the pyrex function. Do I need to convert to array or something so pyrex can generate tight code? I'm not...
3
by: Rafael Tejera | last post by:
I would like to create an history module to my application.. I need some advice to use a duplicate database with who, when and where fields added to that new duplicate table, or create a table...
37
by: Hilton | last post by:
Hi, for (int i = 0; i < list.Count; i++) has a hidden performance hit; i.e. list.Count gets evaluated each time, so we write something like: int listCount = list.Count; for (int i = 0; i <...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.