Q:

C# program to print a message without using the WriteLine() method

belongs to collection: C# Basic Programs | basics

0

C# program to print a message without using the WriteLine() method

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to print a message without using the WriteLine() method is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to print a message without 
//using WriteLine() method

using System;
using System.Text;
using System.IO;

class Sample
{
    static void Main()
    {
        string str = "India";
        
        byte[] msg = Encoding.ASCII.GetBytes(str);

        Stream Ob = Console.OpenStandardOutput();
        Ob.BeginWrite(msg, 0,str.Length, null, null);

        Console.WriteLine();
    }
}

Output:

India
Press any key to continue . . .

Explanation:

In the above program, we created a class Sample that contains the Main() method. In the Main() method, we created a string str initialized with "India".

byte[] msg = Encoding.ASCII.GetBytes(str);

In the above statement, we converted the string into a byte array.

Stream Ob = Console.OpenStandardOutput();
Ob.BeginWrite(msg, 0,str.Length, null, null);

In the above statements, we created the object of Stream class and then write converted byte array on the standard output device that is "Monitor", that's why the message "India" will be printed on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | basics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to convert a temperature from Celsius t... >>
<< C# program to demonstrate the example goto stateme...