To write data to a CSV file using the StreamWriter class in C#, the following steps are essential. First, prepare the data in a suitable format, such as a string with comma-separated values. For example, the data "Bob,1,2,3\nJim,4,5,6\nTom,7,8,9" can be used. Next, specify the file path where the CSV will be saved, such as "C:\test1.txt". Utilize the StreamWriter class to create a new instance, passing the file path, a boolean for appending data, and the encoding type. Use the WriteLine method to write each line of data to the file. After writing, ensure to flush the StreamWriter to save changes and close the file to release resources. This process effectively creates a CSV file with the desired data.