Q:

C# program to demonstrate the StringWriter class

belongs to collection: C# Files Programs

0

C# program to demonstrate the StringWriter class

All Answers

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

Program:

The source code to demonstrate the StringWriter class is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# Program to demonstrate StringWriter class. 

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

public class Demo
{
    public static void Main()
    {
        StringWriter sw = new StringWriter(new StringBuilder());

        sw.WriteLine("\tThis is a cat.");

        sw.WriteLine("\tThis is a dog.");
        sw.WriteLine("\tThis is an elephant.");
        sw.Flush();
        sw.Close();

        Console.WriteLine("Saved Information:");
        Console.WriteLine(sw);
    }   
}

Output:

Saved Information:
        This is a cat.
        This is a dog.
        This is an elephant.

Press any key to continue . . .

Explanation:

In the above program, we created a class Demo that contains the Main() method. The Main() method is the entry point of the program, here we write data into the stream using WriteLine() method of StringWriter class and then print saved information on the console screen.

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

total answers (1)

C# program to read all lines from a file using Str... >>
<< C# program to read the list of available disk driv...