0

NOTE: I have figured out that this only affects .NET fiddle if you are using .NET 6. If you aren't using .NET 6 it works fine.

Whenever I use the Console.WriteLine() function on .NET fiddle, it doesn't let me interact with the console. I'm new at coding and .NET fiddle, so it might be a simple fix. I just hope you can figure it out

I've tried just having the Console.WriteLine. I've triple checked I wrote it right. I rewrote the Convert.ToInt32 several times. I looked up to see if anyone else had this problem. I even checked if Console.WriteLine being under the list maker was the problem, it wasn't.

Here is the code:

using System;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {
        
        List<string> shoppingList = new List<string>();
        
        Console.WriteLine("How many items on the list?");
        
        int listLength = Convert.ToInt32( Console.ReadLine() );
            
        for(var i = 0; i < 4; i++) {
            shoppingList.Add(Console.ReadLine());
        }
        
        for(var i = 0; i < shoppingList.Count; i++) {
            Console.WriteLine(shoppingList[i]);
        }
    }
}
  • 1
    "it doesn't let me" - can you elaborate on what that means? If you place your mouse cursor over the console pane at the bottom after running the code, left-click, and then start typing, does nothing happen? Does an error occur? Does it show a `>` prompt after writing the `How many items on the list?` message? Please be mindful that no one but you can see your screen :) – Mathias R. Jessen Jan 07 '22 at 14:25
  • 1
    DotNetFiddle dev here. If you are trying this with .NET Core 6, then it's a known issue for us with how it works internally. There is similar question here with reasoning - https://stackoverflow.com/questions/67138172/c-sharp-console-application-readline-works-in-net-4-7-2-and-not-in-net-5-on – Sergey Litvinov Jan 07 '22 at 20:08
  • @Lilyofluck we updated it and Console.ReadLine should be working fine now for .NET 3.1\5\6\7\8 – Sergey Litvinov May 03 '23 at 11:56

1 Answers1

2

It's working fine here on my side, as you can see here. Have you tried cleaning the cookies of your browser? Note that you have to click on the console to type. Also, I fixed your function where it gives the correct size of the List<string>.

using System;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {
        
        List<string> shoppingList = new List<string>();
        
        Console.WriteLine("How many items on the list?");
        
        int listLength = Convert.ToInt32( Console.ReadLine() );
            
        for(var i = 0; i < listLength; i++) {
            shoppingList.Add(Console.ReadLine());
        }
        
        for(var i = 0; i < shoppingList.Count; i++) {
            Console.WriteLine(shoppingList[i]);
        }
    }
}
ojonasplima
  • 411
  • 2
  • 12