开发者

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:

  1. Open Watch window

  2. Type name of variable which is list

  3. 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 )

  4. Press Ctrl + C or click right mouse button and select item from drop down 'Copy'

  5. After that you can able to paste your text presentation of list to any text editor.

Copying the contents of a List<string> to text file while debugging


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.

Copying the contents of a List<string> to text file while debugging

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜