image
image
image

Reading a File

image

Though there are several ways to read and write data to a file, the easiest way is to make use of the File class of the System.IO library.  The File class comes with a variety of functionalities to perform different file-related tasks such as creating a new file, reading data from a file, writing and appending data to a file, deleting a file and so on.

In this section, we will see how the File class can be used for reading a file. Before you execute the following script, create a file named “mytext.txt” and place it in the “D” directory. The contents of the text file should look like this:

Hello C# is awesome

You can develop web applications

as well as desktop applications

with it