On Apr 24, 12:27 pm, "Ignacio Machin ( .NET/ C# MVP )"
<ignacio.mac...@gmail.comwrote:
On Apr 24, 11:23 am, Adam Sandler <cor...@excite.comwrote:
On Apr 24, 9:18 am, "Ignacio Machin ( .NET/ C# MVP )"
<ignacio.mac...@gmail.comwrote:
So AddRange expect an ICollection and ArrayList implements
ICollection, so it should work
It doesn't. I've typed the code exactly as it appears in the IDE. I
'm aware that arraylists implements icollection; that is why I used
used AddRange.
ArrayList ar = new ArrayList();
ar.Add(1); ar.Add(2); ar.Add(3);
ArrayList ar2 = new ArrayList();
ar2.AddRange(ar);
Console.WriteLine(ar2.Count);
I just tested it and worked fine
Thanks everyone for their help so far:
Here's everything I have:
In one class here is this:
private ArrayList al = new ArrayList();
public void setWordList(String s)
{
al.Add(s);
}
public ArrayList getWordList()
{
return al;
}
The contents of the arraylist are read from a text file:
public void ReadFromFile(string filename)
{
StreamReader sr;
string s;
sr = File.OpenText(filename);
s = SR.ReadLine();
WordLists wl = new WordLists();
while (s != null)
{
wl.setWordList(a);
s = sr.ReadLine();
}
sr.Close();
}
Yes, I've verified there are items in the arraylist prior to
continuing. Eventually, and based upon what form the user displays, I
want to put the arraylist contents into a richtextbox. So from the
form's constructor, I call this:
public ListEditor()
{
WordLists wl = new WordLists();
ArrayList al = new ArrayList();
al.AddRange(wl.getWordList);
}
The line which reads, al.AddRange(wl.getWordList) has two errors:
Error 1 The best overloaded method match for
'System.Collections.ArrayList.AddRange(System.Coll ections.ICollection)'
has some invalid arguments
Error 2 Argument '1': cannot convert from 'method group' to
'System.Collections.ICollection'
Again, thanks to everyone for their help thus far