I have a problem with this function:
static List<int> transposition(List<List<int>> main_list, int ammount)
{
List<int> return_list = new List<int>();
List<int> b = new List<int>();
List<List<int>> new_list = new List<List<int>>();
new_list = main_list;
int i = 0;
int j = 0;
int x = 0;
int key = 0;
Random rnd = new Random();
foreach (List<int> subList in new_list)
{
x = subList[2];
}
while (i < ammount)
{
i++;
key = rnd.Next(0, x + 1);
while (j < new_list.Count)
{
if (key >= new_list[j][1] && key <= new_list[j][2])
{
List<int> one_element = new List<int>();
one_element.Add(new_list[j][0]);
one_element.Add(new_list[j][1]);
one_element.Add(new_list[j][2]);
one_element.Add(new_list[j][3]);
if (j != 0)
{
b = new_list[j - 1];
new_list[j - 1] = one_element;
new_list[j] = b;
}
}
j++;
}
}
foreach (List<int> element in new_list)
{
return_list.Add(element[3]);
}
return return_list;
}
As you can see I'm passing 'main_list' to this function and the problem is that this list changes in the function. I had the same problem in Python and there I solve the problem by adding [:], like this 'new_list = main_list[:]'. But I haven't found how to do this in c#. Any suggestions?