473,757 Members | 10,754 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 4406
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)someArr ay).Add(42);

Of course it throws a NotSupportedExc eption 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.WriteLi ne(stringList.C ontains("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
1786
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 conditional for each type. Is there a built-in method to obtain the values of an array assigned...
4
7296
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 derivation is wrong e.g. the type can't actually honour this contract.
3
11804
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
4218
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
23439
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 table or whatever), currently named cbAccounts, that can scroll through and maybe select items in the...
4
2563
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 IList<News> list = (IList<News>)news, but IList is not a class, so I tried to create a class that extends...
7
2049
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
2640
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 table of other table? Any example or article that I can read. Sincerely,
37
2194
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
9489
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10072
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9885
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9737
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7286
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5172
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3829
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.