It was for trying to fix a specific problem, but I was trying to get
an answer for a general case. Still, I have noticed that people are
more willing to respond if code is included since it gives them
something concrete to look at.
Yes, that's true. I can't speak for anyone else, but to me when I see a
very vague, open-ended question, it's just too hard sometimes to try to
figure out what the person really wants to know. To answer the overly
vague question would require writing at least one chapter in a book, if
not the whole book.
It is always much better to be as specific as you can. If you want to
generalize based on responses you get from that sort of request, that is
always possible later.
Only because I read Richter's suggestion in CLR via C# that you try to
be as generic in the parameters you pass as you can get away with.
That advice is certainly not bad advice. It appears to me that in this
case, you went a little overboard, since the IEnumerable interface didn't
actually provide the functionality you needed. In other words, you
couldn't get away with using that as your parameter.
Also, I wasn't interested in accessing any of the list items by index,
just pass them along. I hadn't found anything that identified ToArray
as something that AddRange would accept so I didn't realize that List
was needed.
I agree that it is sometimes hard to make the connections implied in the
documentation. The AddRange() method clearly shows that you can pass an
object array ("object[]"). However, knowing where you might get one is
not always the easiest thing.
That said, of course the first place to start is to see where your data is
coming from and then seeing if it offers any direct way to get an array
from it.
[...]
I've gotten into the habit of avoiding arrays unless the size is known
at compile time.
I think that's overly conservative. IMHO, it's a good idea to not use
arrays if you don't know the size in advance of creating it, but this
information may be available at run-time. And the main reason to not use
arrays when you don't know the size in advance is that classes like List<>
offer convenient ways to resize a collection when necessary. I don't
think there's any performance advantage when using an array-based
collection versus an actual array (list-based collections, like
LinkedList<>, obviously do have a performance advantage since you can add
items without having to copy the whole data structure).
Anyway, sounds like you're back on track. Glad to hear it.
Pete