(E-Mail Removed) wrote:
> Your right, that should have read
>
> ds.Tables[0] = new DataTable().
>
> I know you can add a table with ds.Tables.Add. But if I want to
> replace(!) a table I'll have to remove it first and then add the new
> one rather then just replace it like in the statement above. So what
> is the logic behind this limitation?
>
> Again, note that I just take the DataSet as an example. The reason I
> am asking is because I wonder about what should be offered in a custom
> class.
I think part of the reason the DataTableCollection indexer is read-only is
that it isn't always safe to remove a table from the collection. The proper
way to remove a table would be to call CanRemove first and then Remove.
This is due to the relational nature of tables in a dataset. I would think
that if the table at [0] can't be removed then it could lead to confusion as
to why the assigment of ds.Tables[0] = new DataTables() failed.
In your custom class, if it is always safe to remove items then I see no
reason to make the indexer read-only.
--
Tom Porterfield