Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
18 views1 page

MyWriter Cs

The document defines a C# class named MyWriter that extends StreamWriter to facilitate writing different data types to a file. It includes methods to write integers, booleans, and strings, with specific formatting for each type, such as padding integers with zeros and appending 'ENDOFSTRING' to strings. This class is designed to streamline the process of file writing with custom formatting rules.

Uploaded by

Slime UNICORN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views1 page

MyWriter Cs

The document defines a C# class named MyWriter that extends StreamWriter to facilitate writing different data types to a file. It includes methods to write integers, booleans, and strings, with specific formatting for each type, such as padding integers with zeros and appending 'ENDOFSTRING' to strings. This class is designed to streamline the process of file writing with custom formatting rules.

Uploaded by

Slime UNICORN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System;

using System.IO;

class MyWriter : StreamWriter


{
// constructor for MyWriter object
public MyWriter( string fileName )
: base( fileName )
{
} // end constructor

// write integer to file


public void WriteInteger( int output )
{
// pad the integer with zeros
string toWrite = output.ToString().PadLeft( 10, '0' );

Write( toWrite ); // write to file


} // end method WriteInteger

// write boolean to file


public void WriteBoolean( bool output )
{
// a written boolean is 5 characters long
if ( output )
Write( "true " );
else
Write( "false" );
} // end method WriteBoolean

// write string to file


public void WriteString( string output )
{
// each string ends with "ENDOFSTRING"
Write( output + "ENDOFSTRING" );
} // end method WriteString
} // end class MyWriter

You might also like