473,395 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

System.Array inherits from IList ???

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[5]{1,2,5,6,7};
numbers.Add(1) --> NOT POSSIBLE Compiler error : 'System.Array' does
not contain a definition for 'Add'
Array.Add(2) --> NOT POSSIBLE Compiler error : 'System.Array'
does not contain a definition for 'Add'

nor some belonging to ICollection : SyncRoot:yes, Count:no
numbers.Count --> NOT POSSIBLE

IEnumerable : no problem

What is reasoning behind all this ?
Already does intelisense not show those functions. But why not ? if the
specs make you suppose you could use them.

I thought maybe 'cause the functions are abstract so you must implement them
yourself (such as IList::Add) but then again , IEnumerable:GetEnumerator()
is an abstract function as well and I can use that one, no problem.

Thanks in advance

Chris

Nov 15 '05 #1
3 11774
Chris,

If a class implements an interface, it doesn't have to expose those
members publically. In order to access the IList functionality on an array,
you must assign to an IList reference, like so:

// Get the IList.
IList pobjArray = new int[1]{1};

You can set pobjArray equal to any array reference.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Chris" <ch********@pandora.be> wrote in message
news:xT*********************@phobos.telenet-ops.be...
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[5]{1,2,5,6,7};
numbers.Add(1) --> NOT POSSIBLE Compiler error : 'System.Array' does not contain a definition for 'Add'
Array.Add(2) --> NOT POSSIBLE Compiler error : 'System.Array'
does not contain a definition for 'Add'

nor some belonging to ICollection : SyncRoot:yes, Count:no
numbers.Count --> NOT POSSIBLE

IEnumerable : no problem

What is reasoning behind all this ?
Already does intelisense not show those functions. But why not ? if the
specs make you suppose you could use them.

I thought maybe 'cause the functions are abstract so you must implement them yourself (such as IList::Add) but then again , IEnumerable:GetEnumerator()
is an abstract function as well and I can use that one, no problem.

Thanks in advance

Chris


Nov 15 '05 #2
ah yes. of course !
Thnx for your quick response

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eX*************@tk2msftngp13.phx.gbl...
Chris,

If a class implements an interface, it doesn't have to expose those
members publically. In order to access the IList functionality on an array, you must assign to an IList reference, like so:

// Get the IList.
IList pobjArray = new int[1]{1};

You can set pobjArray equal to any array reference.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Chris" <ch********@pandora.be> wrote in message
news:xT*********************@phobos.telenet-ops.be...
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[5]{1,2,5,6,7};
numbers.Add(1) --> NOT POSSIBLE Compiler error : 'System.Array'

does
not contain a definition for 'Add'
Array.Add(2) --> NOT POSSIBLE Compiler error : 'System.Array' does not contain a definition for 'Add'

nor some belonging to ICollection : SyncRoot:yes, Count:no
numbers.Count --> NOT POSSIBLE

IEnumerable : no problem

What is reasoning behind all this ?
Already does intelisense not show those functions. But why not ? if the
specs make you suppose you could use them.

I thought maybe 'cause the functions are abstract so you must implement

them
yourself (such as IList::Add) but then again , IEnumerable:GetEnumerator() is an abstract function as well and I can use that one, no problem.

Thanks in advance

Chris



Nov 15 '05 #3
"Chris" wrote...
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

What is reasoning behind all this ?
An array is a special case of an IList, which have been handled based on the
fact that an array has a fixed size.
I thought maybe 'cause the functions are abstract so
you must implement them yourself (such as IList::Add) ...


It *is* implemented.

<quote>
Array.IList.Add

Implements IList.Add. Always throws NotSupportedException.

Array has a fixed size; therefore, elements cannot be added or removed. Use
SetValue to change the value of an existing element.

</quote>

You can read more in the documentation:

http://msdn.microsoft.com/library/de...staddtopic.asp

If the above link wraps, you can use this instead:

http://tinyurl.com/wny0

// Bjorn A
Nov 15 '05 #4

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

Similar topics

2
by: tsteinke | last post by:
I noticed somthing. The native Array Types implement the IList interface. However they do not contain all the methods in the interfaces they implement. for example... int test=new int;...
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...
2
by: Chris | last post by:
Hi, the specs for System.Array are : MustInherit Public Class Array Implements ICloneable, IList, ICollection, IEnumerable but I can't use any of the functions presented by IList in my code ...
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...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
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...
6
by: Arthur Dent | last post by:
How do you sort a generic collection derived from System.Collections.ObjectModel.Collection? Thanks in advance, - Arthur Dent
0
by: Martin Henke | last post by:
Dear all, I've got a problem with my custom combo box. When I select an entry from it, then I get the error message: "An unhandled exception of type 'System.ArgumentOutOfRangeException'...
2
by: Tony Johansson | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
0
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...

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.