I am facing an annoying issue when I am trying to copy an array. The new array keeps a relation even if it's created by .copy() method. Here is the situation,
Main Class
Dictionary<string, string>[] DataCurrentDict = new Dictionary<string, string>[result.Data.Count()];
// 1. Here the DataCurrentDict array is filled with values, having DataCurrentDict[0]["Weight"] = "0.345";
ProductData CurrentProductData = new ProductData(DataCurrentDict);
// 2. Here, the CurrentProductData._ProductDataDict[0]["Weight"] = "0.345", GOOD
DataCurrentDict[0]["Weight"] = "1111";
// 3. Here is the problem... After setting a value into DataCurrentDict, the copied array is modified too! So CurrentProductData._ProductDataDict[0]["Weight"] = "1111" ...Why?
ProductData Class
public class ProductData : IDisposable
{
private Dictionary<string, string>[] _ProductDataDict;
//CONSTRUCTOR
public ProductData(Dictionary<string, string>[] ProductDataDict)
{
try
{
_ProductDataDict = new Dictionary<string, string>[ProductDataDict.Count()];
Array.Copy(ProductDataDict, _ProductDataDict, ProductDataDict.Length);
}
catch (Exception ex) { }
}