Reputation: 29178
I need to compare the contents of a List for two runs for my program. What is the easiest way to copy the entire contents of the List manually from Visual Studio to notepad while stepping through the code. I can view the contents in QuickWatch. How can I copy all the elements?
Upvotes: 24
Views: 44808
Reputation: 7385
Open Watch window
Type name of variable which is list
Select items which need ( for whole selection press 'shift' and click on first element and after that click on the last element of the list )
Press Ctrl + C or click right mouse button and select item from drop down 'Copy'
After that you can able to paste your text presentation of list to any text editor.
Upvotes: 7
Reputation: 2559
I thinks this solution is better than.
List<string> list = new List<string>();
list.Add("test1");
list.Add("test2");
list.Add("test3");
list.Add("test4");
File.WriteAllLines(Application.StartupPath + "\\Text.txt", list.ToArray());
Process.Start("notepad.exe", Application.StartupPath + "\\Text.txt");
Upvotes: 8
Reputation: 22683
Simply type this into the immediate window:
File.WriteAllLines("foo.txt", yourList);
Or if it's a list of something other than strings:
File.WriteAllLines("foo.txt", yourList.ConvertAll(Convert.ToString));
Upvotes: 35
Reputation: 47530
Do a QuickWatch. In the quick watch window you can copy the values you want. If you want you can add some code to the top textbox in that window.
Upvotes: 2
Reputation: 93030
You can open the immediate window and run something like:
string.Join(", ", yourList)
or just
yourList
To open the immediate window: Debug -> Windows -> Immediate or the equivalent Ctrl+D, I
Upvotes: 24