471,348 Members | 1,298 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Re: Which generic?

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

class Column Collection : List<Column>
Column this[string someName]
foreach(Column col in this)
if (string.Equals(col.ColumnName, someName,
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.

Jul 2 '08 #1
0 762

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Seth Gecko | last post: by
13 posts views Thread by rkausch | last post: by
15 posts views Thread by Lloyd Dupont | last post: by
2 posts views Thread by ADN | last post: by
26 posts views Thread by raylopez99 | last post: by
1 post views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.