When iam adding a DatagridviewRow to a Dictionary and Delete the DatagridviewRow also the Datagridviewrow in Dictionary changes. But i dont want the Dictionary to change
Dictionary<int, CustomDataGridViewRow> _cache = new Dictionary<int, CustomDataGridViewRow>();
public void add(int index, CustomDataGridViewRow row)
{
_cache.Add(index, row);
}
this.Rows.RemoveAt(1);
I tried a to clone the row, but i dont make a copy of the row, it makes a new row. look at this:

Then you need to clone the object before you add the dictionary entry.
A dictionary doesn’t contain objects – it contains references. The dictionary itself isn’t changing – it just contains a reference to the object which has changed.
If your object supports cloning, you can just use:
You may want to see the docs for
DataGridViewRow.Clonefor more details though…Either way, it’s very important that you understand how reference types work in C#, otherwise you’ll keep bumping into this time and again.