Modified Hello world sample shows strange behavior
Steps to reproduce
Follow the steps given at [https://www.microsoft.com/net/core#windows] and use the following modified version of Hello world program:
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.Write("Enter a number to see magic: ");
int num = Convert.ToInt32(Console.ReadLine());
for(int i=0; i <=num; i++)
{
Console.WriteLine(i);
}
}
}
}
Expected behavior
The program should roduce the following as ouptut(Let us suppose user enters 5): Hello World! Enter a number to see magic: 5 1 2 3 4 5
Actual behavior
The program gives the following as ouptut(Let us suppose user enters 5): Hello World! 5 Enter a number to see magic: 1 2 3 4 5
Environment data
dotnet --info output:
.NET Command Line Tools (1.0.0-preview1-002702)
Product Information: Version: 1.0.0-preview1-002702 Commit Sha: 6cde21225e
Runtime Environment: OS Name: Windows OS Version: 6.1.7601 OS Platform: Windows RID: win7-x64
Hi, I don't see any problem with the above code.I have the same environment data as yours and when i run the above code, it works fine for me.No errors for me.The expected behaviour is what i got.Try restarting the VS and run again.
@sravan1022 I am using the "dotnet cli" to run the program. The issue above gives you the exact steps to follow, when you follow the provided link. I know that this runs in visual studio but when I run it using dotnet run command, it gives me the strange output as given above.
It would be nice, if .NET Core would ensure that stdio is flushed, before reading the input. Might be a corefx problem?
I believe @eerhardt fixed this recently.
Yes, this issue was fixed with dotnet/cli#3013, but it didn't make it into "Preview1". It is only fixed in the latest "Preview2" nightly builds.
You can work around this issue for now by saying 'dotnet path-to-your-assembly.dll' instead of calling 'dotnet run'.