convertion from CollectionBase to string []

  • Thread starter Thread starter juli
  • Start date Start date
J

juli

I am trying to convert an object of a class which is derived from
collectionbase class.It's not working:
while ((line = file.ReadLine()) != null && line.IndexOf(" ")!=-1)
{
al.Add(line);


}
string[] exc_string = (string[])al.ToArray(typeof(string));

somebody know why?
Thank you!
 
Without a repro case and information about what it is that goes wrong
exactly it is hard to tell.

/Joakim
 
ArrayList al = new ArrayList();
while ((line = file.ReadLine()) != null && line.IndexOf(" ")!=-1)
{
al.Add(line);


}
string[] exc_string = (string[])al.ToArray(typeof(string));

That's my program.Could u tell me why convertion faild?
Thanks!
 
ArrayList al = new ArrayList();
while ((line = file.ReadLine()) != null && line.IndexOf(" ")!=-1)
{
al.Add(line);


}
string[] exc_string = (string[])al.ToArray(typeof(string));

That's my program.Could u tell me why convertion faild?
Thanks!
 
"It's not working" is not a sufficient statement of the problem. What is
the exact error you're getting?

--Bob
 
Not without some more information I'm afraid. Could you

1. Describe what kind of failure you see. Do you get an exception? Get
corrupted data?

2. Could you post a short but complete program (as Jon likes to put it).

/Joakim
 
juli jul said:
ArrayList al = new ArrayList();
while ((line = file.ReadLine()) != null && line.IndexOf(" ")!=-1)
{
al.Add(line);


}
string[] exc_string = (string[])al.ToArray(typeof(string));

That's my program.Could u tell me why convertion faild?

No, that's not your program. It's a small part of your program.Further,
as Joakim said, you haven't provided any sample data.

Please read http://www.pobox.com/~skeet/csharp/complete.html
 
There isnt anything wrong with the code, Break on the line at the end of the
code snippet and check the contents of the ArrayList.

Ciaran
 
Back
Top