I posted for help on converting the newlines ArrayList to an array of String and got a reply that showed how to do it. The trick was the typeof function, which I had forgotten about since C days so long ago. I promised to fix it when I learned a better way and had nothing else to do after dinner, so I decided to clean up the code a bit more. Remember that we had this:
public String[] Lines {
get {
// there must be a way to cast this??
String[] textlines = new String[newlines.Count];
for (int i = 0; i < newlines.Count; i++) {
textlines[i] = (String) newlines[i];
}
return textlines;
}
set {
lines = new ArrayList(value);
newlines = lines;
}
}
It s that ugly get of the Lines property that I m trying to fix. Sure enough, this approach works just fine:
public String[] Lines {
get {
return (String[]) lines.ToArray(typeof(String));
}
set {
lines = new ArrayList(value);
}
You would think that a reasonable language wouldn t have needed two hints that both say, Hey, this is an array of strings. Still, this is much better.