Search code examples
c#visual-studio-codedotnet-interactive.net-interactive

.NET Interactive - how to change collection output size


I'm using .NET Interactive notebook inside VS Code and want to change the number of printed out elements:

var x = Enumerable.Range(0,21);
x.Display();

Only first 20 element are shown in the the output:

enter image description here

Can I somehow increase the size of output?


Solution

  • You can use Formatter from Microsoft.DotNet.Interactive.Formatting namespace to change the size of the output:

    using Microsoft.DotNet.Interactive.Formatting; 
    Formatter.ListExpansionLimit = 25;
    

    Docs:

    • Formatter.ListExpansionLimit = 20

      Gets or sets the limit to the number of items that will be written out in detail from an IEnumerable sequence.

    • Formatter<T>.ListExpansionLimit = (not set)

      An optional type-specific list expansion limit