Here's some c# code:

using System;
using System.Collections;
namespace AdapterProblem
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
ArrayList source = ArrayList.Adapter(new object [] {"1" , "2"});
ArrayList range = source.GetRange(1,1);
ArrayList target = new ArrayList();
target.AddRange(range);
Console.WriteLine(target[0] == null? "It's null" : target[0]);
Console.ReadLine();
}
}
}

I would expect this to print out the second element of source -
i.e. the string "2". Actually it turns out that target[0] is null so
the program prints "It's null".

Is this a bug? If this behaviour is as it should be could someone
please explain why?

Re: ArrayList adapter problem by William

William
Thu Nov 04 09:04:33 CST 2004

It seems. As the range is a "view" into source, using the range as
ICollection for AddRange must have something to do with this. Not sure if
that usage of a Range is supported or not?

--
William Stacey, MVP
http://mvp.support.microsoft.com

"Paul Rudin" <Paul_Rudin@scientia.com> wrote in message
news:u4qk5g9bi.fsf@scientia.com...
>
> Here's some c# code:
>
> using System;
> using System.Collections;
> namespace AdapterProblem
> {
> class Class1
> {
> [STAThread]
> static void Main(string[] args)
> {
> ArrayList source = ArrayList.Adapter(new object [] {"1" , "2"});
> ArrayList range = source.GetRange(1,1);
> ArrayList target = new ArrayList();
> target.AddRange(range);
> Console.WriteLine(target[0] == null? "It's null" : target[0]);
> Console.ReadLine();
> }
> }
> }
>
> I would expect this to print out the second element of source -
> i.e. the string "2". Actually it turns out that target[0] is null so
> the program prints "It's null".
>
> Is this a bug? If this behaviour is as it should be could someone
> please explain why?


Re: ArrayList adapter problem by Paul

Paul
Fri Nov 05 03:07:47 CST 2004

>>>>> "WS" == William Stacey [MVP] <William> writes:

WS> It seems. As the range is a "view" into source, using the range
WS> as ICollection for AddRange must have something to do with this.
WS> Not sure if that usage of a Range is supported or not?

Thanks for your reply. How would one know whether it's "supported" or
not? GetRange returns an ArrayList which supports the ICollection
interface... AddRange shouldn't presumably be relying on anything
else. However the problem does appear to be something to do
ArrayList.Adapter since it doesn't arise without this.

The slightly strange thing is that other obvious tests of the result
of the call to GetRange seem to give sensible results...