13.4. Types of Files

From a programming language point of view, there are two basic types of files: those that contain textual data and those that contain binary data. Often you can determine if a given file is a text or binary file by its name. File names are stored on disk using a primary and secondary file name. For example, a file named PamAtParty.jpg has a primary name of PamAtParty and a secondary file name of jpg. (Many people refer the primary file name as the file name and the secondary file name as the file's extension.) The secondary file name often gives a clue as to its type. For example, a file extension of txt is normally a textual data file while those ending in jpg are binary image files. While there is nothing that requires you to use common file extensions, it's usually a good idea to employ them in your own programs.

13.4.1. Textual Versus Binary Data Files

Files that contain textual data are usually built from strings appended to the file. When a user types text into a textbox, that data is stored in memory as plain text in a string format. If you wish to save that information permanently on disk, it means moving the strings from memory to a disk data file. If the user types a number into a textbox and that number is used numerically (for example, if the square root of that number is taken), the number is stored in memory in a binary format. For that number to be saved in a text file, it must be converted to a string and then written to disk. In other words, ...

Get Beginning C# 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.