static void Main(string[] args) { var node1 = new ListNode() { Data = "1" }; var node2 = new ListNode() { Data = "2" }; var node3 = new ListNode() { Data = "3" }; var node4 = new ListNode() { Data = "4" }; var firstList = new ListRandom(node1); firstList.Add(node2); firstList.Add(node3); firstList.Add(node4); using (FileStream fs = new FileStream("list.txt", FileMode.Create)) { firstList.Serialize(fs); } var secondList = new ListRandom(); using (FileStream fs = new FileStream("list.txt", FileMode.Open)) { secondList.Deserialize(fs); } Console.WriteLine("firstList \t secondList"); for (int i = 0; i < firstList.Count; i++) { Console.WriteLine("data:{0} \t {1}", firstList.Get(i).Data, secondList.Get(i).Data); Console.WriteLine("rand:{0} \t {1}", firstList.Get(i).Random.Data, secondList.Get(i).Random.Data); } Console.ReadLine(); }
private ListRandom GetListRandom(int countNodes) { var list = new ListRandom(); for (int i = 0; i < countNodes; i++) { list.AddWithoutRandom(i.ToString()); } list.ForEachStoppable((ListNode node, ref bool stop) => { node.Random = list.Get(_random.Next(0, list.Count - 1)); }); return(list); }