Answer the question
In order to leave comments, you need to log in
How to clone sublists for a list of lists in C#?
For example, there is this code:
LinkedList<LinkedList<String>> l = new LinkedList<LinkedList
<String>>();
LinkedList<String> ll = new LinkedList<String>();
ll.AddLast("Masha");
ll.AddLast("Masha");
ll.AddLast("Masha");
ll.AddLast("Masha");
LinkedList<String> lll = new LinkedList<String>();
lll.AddLast("Sveta");
lll.AddLast("Sveta");
lll.AddLast("Sveta");
lll.AddLast("Sveta");
l.AddLast(ll);
l.AddLast(lll);
ll.AddFirst("WARNING!!!"); \\ Как сделать так, чтобы ll в l при этом не изменялся?
foreach (LinkedList<string> i in l)
{
foreach(string s in i)
{
System.Console.Write(s+ ' ');
}
}
WARNING!!! Masha Masha Masha Masha Sveta Sveta Sveta Sveta
Answer the question
In order to leave comments, you need to log in
Write your own class that will implement the desired logic for adding elements
What are you actually trying to implement? Wood? Or what in general? Your implementation now looks at least strange, and it's not obvious what you're trying to implement. Without a task to say how to do it right is difficult.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question