System.Array inherits from IList ???

C

Chris

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


Dim numbers As System.Array
numbers.Add(1) --> 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.

Thanks in advance

Chris
 
H

Herfried K. Wagner [MVP]

* "Chris said:
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


Dim numbers As System.Array
numbers.Add(1) --> 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.

The interfaces are explicitly implemented (a feature, VB.NET doesn't
provide).
 
M

Mark Hurd

Herfried said:
The interfaces are explicitly implemented (a feature, VB.NET doesn't
provide).

No, they just haven't made the methods public on the class, (the default
interface in VB6/COM speak) or not with the same name.

Eg. Array.Length Implements ICollection.Count

(Proof:
With GetType(System.Array)
System.Console.WriteLine( _
.GetMethod("Length") _
Is .GetMethod("Count", New System.Type() _
{GetType(System.Collections.ICollection)}))
End With

displays True.(*))

BTW IList.Add on an Array always fails with System.NotSupportedException,
message: Collection was of a fixed size.
--
Regards,
Mark Hurd, B.Sc.(Ma.) (Hons.)


(*) That looks convoluted enough to just use ILDASM and determine it from
there, but it's acually my (tested) conversion from this DotLisp test:
(eql? (.GetMethod Array. "Length")(.GetMethod Array. "Count"
[ICollection.]))
True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top