skip to Main Content

I have this code

int[] Array = { 0, 1, 2, 3, 4, 5 };
int i;

for (i = 0; i < 6; i++)
    Console.Write(" " + Array[i]);

Console.WriteLine("n New Array");
Array = new int[] { 99, 10, 100, 18, 78, 23, 163, 9, 87, 49 };

for (i = 0; i < 10; i++)
{
    Console.Write(" " + Array[i]);
}

Console.ReadLine();

I am using Visual Studio Code :

Version: 1.82.0

Electron: 25.8.0

ElectronBuildId: 23503258

Chromium: 114.0.5735.289

Node.js: 18.15.0

V8: 11.4.183.29-electron.0

OS: Linux x64 5.15.0-83-generic

This code runs fine on Windows, but on Linux, instead of

0 1 2 3 4 5 
New Array 
99 10 100 18 78 23 163 9 87 49

I get

0 1 2 3 4 5
New Array

2

Answers


  1. in Console.WriteLine("n New Array");
    propably /n is correct

    Login or Signup to reply.
  2. When you write data (e.g., text) to stdout in Linux, the system doesn’t immediately send that data to the screen. Instead, it collects the data in a temporary storage area known as a buffer.

    The purpose of buffering is to reduce the number of system calls needed to write data to the output device. Writing data in smaller, frequent chunks can be less efficient than writing it in larger, less frequent chunks.

    Under certain conditions, buffers are automatically flushed, such as when the buffer becomes full, or when a newline character (‘n’) is encountered. That is the case with WriteLine.

    However, Console.Write doesn’t flush the buffer, so a simple way to fix this, should be to add a new line character at the end.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search