In my program I found that when asssigning a variable to another, modifying the first one, also modifies the second.
Example:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace Dict_test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void TestButton_Click(object sender, EventArgs e)
{
Dictionary<string, int> Dict1 = new Dictionary<string, int>();
Dict1.Add("one", 1);
Dict1.Add("two", 2);
Dictionary<string, int> Dict2 = new Dictionary<string, int>();
Dict2 = Dict1;
Dict1.Remove("two");
MessageBox.Show(Dict2["two"].ToString());
}
}
}
Is there a way to make sure that Dict2 doesn't change when changing Dict1.
If possible without const Dict2
I come from a python environement and find this very disturbing
Thanks in advance :)