The document defines a custom reader class that inherits from the StreamReader class and adds methods to read specific data types from a file. The class contains constructors and methods to read integers, booleans, and strings from a file.
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 ratings0% found this document useful (0 votes)
15 views2 pages
MyReader Cs
The document defines a custom reader class that inherits from the StreamReader class and adds methods to read specific data types from a file. The class contains constructors and methods to read integers, booleans, and strings from a file.
public bool ReadBoolean() { // for reading a boolean char[] buffer = new char[ 5 ]; string toRead = string.Empty;
// read either 'true' or 'false'
Read( buffer, 0, 5 );
toRead = new string( buffer );
return toRead.Trim() == "true";
} // end method ReadBoolean
// read in string from file
public string ReadString() { // for reading a string char[] buffer = new char[ 1 ]; string input = string.Empty;
// each string is separated by "ENDOFSTRING";
// read in one character at a time until termination // string is reached while ( input.LastIndexOf( "ENDOFSTRING" ) == -1 ) { Read( buffer, 0, 1 ); input += buffer[ 0 ]; } // end while
// trim the termination string off the read string
return input.Substring( 0, input.LastIndexOf( "ENDOFSTRING" ) ); } // end method ReadString } // end class MyReader