Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Immediate Window output programmatically

I have an application that is implementing its own C# console (via Roslyn's scripting engine). I already got the code to execute a statement and got the possible return value and now I would like to output a "nice" string to the console. The trivial approach to call "ToString()" will usually have very human unreadable output.

The best solution for me would be to have the same kind of inspection output that the "Immediate Window" of Visual Studio uses.

So for example if my statement evaluates to a new string[]{"asd"}, then just calling ToString() would give me

System.String[]

where I would like to have the equivalent output of the Immediate Window - something like this:

{string[1]}
    [0]: "asd"

So does anyone knows how to call the same convertion that the Immediate Window uses?

like image 369
Imi Avatar asked Mar 15 '26 07:03

Imi


1 Answers

It appears you have an array of Strings containing a single String, and you call .ToString() against the array. Try to replace

.ToString()

with

[0].ToString()

and see if that would give you the expected result.

like image 186
Daniel Avatar answered Mar 17 '26 20:03

Daniel