Skip to content
Related Articles

Related Articles

C# Program to Print Hello World Without Using WriteLine

Improve Article
Save Article
  • Last Updated : 01 Nov, 2021
Improve Article
Save Article

Hello World program is the most basic program of any programming language. It prints “Hello world” on the screen. In this article, we will display “Hello World” without using WriteLine Method. So to do this task we use the following methods:

  • Console.OpenStandardOutput(): This method is used to acquire the standard output stream.
  • Console.ReadKey(): This method is used to get the next character pressed by the user and this press key will be displayed in the console window.
  • BeginWrite(): This method is used to begin an asynchronous write operation.
  • AsyncWaitHandle.WaitOne(): This method is used to wait for an asynchronous operation to complete.

For writing Hello World we are taking each separate character in ASCII format and then we are displaying these characters together. 

String H e l l o   W o r l d
ASCII Code 72 101 108 108 111 32 87 111 114 108 100

Approach

1. Inside if condition, Write OpenStandardOutput() to display the Hello World.

2. This method is followed by BeginWrite() method that takes integer Bytes.

BeginWrite(new byte[] { 072, 101, 108, 108, 111, 032, 087, 111, 
                        114, 108, 100, 0 }, 0, 12, null, null)

3. Finally we are using AsyncWaitHandle.WaitOne() method followed by BeginWrite() method.

BeginWrite(new byte[] { 072, 101, 108, 108, 111, 032, 087, 111, 
                        114, 108, 100, 0 }, 0, 12, null, 
                        null).AsyncWaitHandle.WaitOne()) 

Example:

C#




// C# program to display Hello World without
// using WriteLine() method
using System;
  
class GFG{
  
static void Main(string[] args)
{
      
    // ASCII values for Hello World
    if (System.Console.OpenStandardOutput().BeginWrite(new byte[] { 
        072, 101, 108, 108, 111, 032, 087, 111, 114, 108, 100, 0 }, 
        0, 12, null, null).AsyncWaitHandle.WaitOne()) 
    
    }
}
}


Output:

Hello World
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!