Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Visual Studio when debugging C# code, can I export a List or a Dictionary in xml,csv or text format easily?

In Visual Studio when debugging C# code, can I export a Dictionary<string,string> in xml,csv or text format easily?

I would like to export a Dictionary<string,string> in excel and see 2 columns of strings.

Debugging such dict in VS is cumbersome.

If there s any add on that simplifies visualization that s ok too.

like image 338
Fred Avatar asked Dec 14 '16 00:12

Fred


People also ask

Can you debug C in Visual Studio?

Visual Studio Code supports the following debuggers for C/C++ depending on the operating system you are using: Linux: GDB. macOS: LLDB or GDB. Windows: the Visual Studio Windows Debugger or GDB (using Cygwin or MinGW)

How do you debug C code in Visual code?

vscode folder. VSCode can create and auto-configure these files if we try to debug for the first time. To do that, open C++ file in VSCode and either hit F5 or go to Debug -> Start Debugging and select C++ (GDB/LLDB) then select g++.exe build and debug active file .

How do I run and debug C in Visual Studio?

message, choose the Install more tools and features link. Then, in the Visual Studio Installer, choose the Desktop development with C++ workload. In the Configure your new project window, type or enter get-started-debugging in the Project name box. Then, choose Create.

Is there C in Visual Studio code?

C/C++ support for Visual Studio Code is provided by a Microsoft C/C++ extension to enable cross-platform C and C++ development on Windows, Linux, and macOS.


2 Answers

You can add a watch to your Dictionary (or List), then under the Watch Window you can then expand the entire dictionary (or List), right click, select-all, copy

Export

Then in Excel you can paste the data and it should auto-format:

Excel

You could also just paste this data directly into another text-editor (or just view the data directly in the watch window too).

Hope that can help.

like image 178
txtechhelp Avatar answered Sep 21 '22 18:09

txtechhelp


You could use a simple snippet like this:

var output = dict.Select(kv => string.Format("{0},{1}", kv.Key, kv.Value)); File.WriteAllLines("output.csv", output); 

As noted in the comments, if your dictionary keys or values contain any commas or newlines, you'll need something slightly more complex to generate valid a CSV file.

like image 28
Blorgbeard Avatar answered Sep 21 '22 18:09

Blorgbeard