Copying the contents of a List<string> to text file while debugging
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?
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));
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
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");
Easiest way:
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.
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.
精彩评论