LINQ create arraylist output

R

raulavi

thanks for any help
vs2008 c# linQ
ArrayList lines = new ArrayList();
(having many lines on this arraylist)
how to replace words and create an new arraylist ?
this is my current code
foreach (string line in lines)
{

ArrayList l2 = new ArrayList();
string l;
l = line.Replace("whatTable", tableName);
l = l.Replace("whatForm", formName);
l2.add(l);
}
 
M

Martin Honnen

raulavi said:
ArrayList lines = new ArrayList();
(having many lines on this arraylist)

Why are you not using a List said:
how to replace words and create an new arraylist ?

List<string> lines = new List<string>() { "foo", "bar", "foobar" };
List<string> newList = lines.Select(s => s.Replace("foo",
"bar")).ToList();


If you really have an ArrayList lines then use
lines.Cast<string>().Select(..)
but you will get an IEnumerable<string> as the LINQ result or a
List<string> if you call ToList().
 

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