Problem Description:
A list that holds struct, and if the struct data is added to another list again,
Changing the value in the struct in the second list will affect the first list.
Now use the code to prove:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Data;
Namespace CSharp {class Program {public int a = 1;
public int b = 2;
Internal struct Info {public int c;
public int D;
public static void Main (string[] args) {ListCopy2 ();
public static void ListCopy2 () {//First list, element type struct, internally containing two cosmetic values
list<info> ls = new list<info> ();
Info info = new info ();
Initializes the two values info.c = 2;
INFO.D = 3; Add this struct to the list of LS.
ADD (info);
The second list, which has the same element type as the element type in the first list list<info> LS2 = new list<info> (); Adds the first element in the first list to the second list LS2.
ADD (Ls[0]);
Remove this value from the second list and reassign Info Info2 = ls2[0]; The assignment is 4 info2.c = 4;
Ls2[0] = Info2;
Print View effect Console.WriteLine (LS[0].C);
Console.WriteLine (LS2[0].C);
Console.readkey ();
}
}
}
Experimental results:
The results show that there is no mutual influence.