In .Net 1.1, DataRowCollection.Clear calls DataTable.Clear
However, there is a difference in .Net 2.0. If I understood the source correctly, DataTable.Clear will clear the unattached rows (created using DataTable.NewRow ), whereas DataRowCollection.Clear will not.
The difference lies in RecordManager.Clear (source below, from the .NET Reference Source for v3.5 SP 0); clearAll true only when called from DataTable.Clear .
internal void Clear(bool clearAll) { if (clearAll) { for(int record = 0; record < recordCapacity; ++record) { rows[record] = null; } int count = table.columnCollection.Count; for(int i = 0; i < count; ++i) { // DataColumn column = table.columnCollection[i]; for(int record = 0; record < recordCapacity; ++record) { column.FreeRecord(record); } } lastFreeRecord = 0; freeRecordList.Clear(); } else { // just clear attached rows freeRecordList.Capacity = freeRecordList.Count + table.Rows.Count; for(int record = 0; record < recordCapacity; ++record) { if (rows[record]!= null && rows[record].rowID != -1) { int tempRecord = record; FreeRecord(ref tempRecord); } } } }
SLaks
source share