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.
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.
Output:
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".
In the above statement, we converted the string into a byte array.
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.