473,520 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4394
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
1762
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 user creates an array and passes it to the obj property, I'm having trouble figuring out an easy way to obtain the values in the array without using a...
4
7274
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 from an interface and only implementing some of it means something is wrong: either the interface specification is wrong e.g. not minimal or the...
3
11790
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 System.Array numbers = new int{1,2,5,6,7}; numbers.Add(1) --> NOT POSSIBLE Compiler error : 'System.Array' does
3
4204
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
23412
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 AcctArray is loaded from a Quickbooks table, so there's no intrinsic dataset to assign as datasource.... I want to have a combo table (or list...
4
2548
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 provided me an array of objects - News, but VS 2005 seams only accept Collections like IList<News> for DataBinding. I can convert an array to...
7
2032
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 clear how to do this.
3
2627
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 with a character field saying which fields have been affected and others fields with who, when and where. What is the best way to keep an historical...
37
2149
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 < listCount; i++)
0
7204
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7602
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5742
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5127
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3282
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3280
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
837
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
506
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.