简体   繁体   中英

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.

在此输入图像描述

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.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM