Skip to content

foreach loop printing elements multiple times #4081

@EngBuilds

Description

@EngBuilds

Describe the bug

The foreach loop isn't functioning correctly.

Code:

// Generate 5 numbers and print them
var numbers = new List<int> { 10, 20, 30, 40, 50 };

foreach (var num in numbers)
{
    Console.WriteLine($"Number: {num}");
}

Output screenshot :

Image

Other observations:
I tried creating a new .dib notebook and couldn't recreate this.
In the notebook that is having this issue, I tried clearing cell outputs, restarting the kernel etc. but it still kept showing this error.

Curious what may have triggered this behavior in the first place.

Please complete the following:

Which version of .NET Interactive are you using? (In a notebook, run the #!about magic command. ): Version: 1.0.632301+7d35ce3be7eb7a603527a3683b691d5e9922adca
Library version: 1.0.0-beta.25323.1+7d35ce3be7eb7a603527a3683b691d5e9922adca

  • OS
    • Windows 11
    • Windows 10
    • macOS
    • Linux (Please specify distro)
    • iOS
    • Android
  • Browser
    • Chrome
    • Edge
    • Firefox
    • Safari
  • Frontend
    • Jupyter Notebook
    • Jupyter Lab
    • nteract
    • Visual Studio Code
    • Visual Studio Code Insiders
    • Visual Studio
    • Other (please specify): .dib file polyglot notebook

Screenshots

If applicable, please add screenshots of the entire VS Code window.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions