By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,451 Members | 1,588 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,451 IT Pros & Developers. It's quick & easy.

Re: Which generic?

P: n/a
qg**********@mailinator.com wrote:
What about just extending List<T>

class Column Collection : List<Column>
{
Column this[string someName]
{
get
{
foreach(Column col in this)
{
if (string.Equals(col.ColumnName, someName,
StringComparison.Ordinal))
return col;
}

return null;
}
}
}
This is a workable solution, however:

- It doesn't implement IDictionary<string, Column>, so it can't be passed to
methods that operate on dictionaries, even though this container logically
is one. Of course, this is a relatively minor issue if you never plan on
doing that anyway.

- It doesn't scale for many columns or for many lookups, since lookup takes
time linear to the number of columns (rather than near-constant time if a
dictionary is used). This may not be an issue if you only ever plan to use
it for a small number of columns, but then you should clearly document that
this is how the class should be used.

- Because it extends List rather than aggregating it, it can't maintain
additional invariants. In particular, it's possible to add a column with the
same name twice. The lookup by name will only ever return one of these
elements. This is unlikely to be what you want.

--
J.
Jul 2 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.