Did you mean CSV (Comma-separated Values)?
There is nothing in this code which should fail, but it does not look like you're trying to write a CSV file, it writes a single CSV line. The code is pretty bad. You hard-code everything using immediate constants. Take the constant of 5. What is there are more components? Why array of 5 values + 5 separate named variables. Do not Repeat Yourself (D.R.Y.). You read the variable and later put values in the array anyway. Instead of "" use
string.Empty
. Close file in the finally section of
try
-
catch
-
finally
block. Never use "
\r\n
", use portable
System.Environment.NewLine
.
Even better, use correct combination or
Write
and
WriteLine
. You console input is ugly due to using only
WriteLine
…
[EDIT]
As I understand from your comment, you wanted to append new data to the same file.
In this case, you should add boolean parameter
append
to the constructor of
StreamWriter
:
http://msdn.microsoft.com/en-us/library/36b035cb.aspx[
^].
(This is kind of bad; it you are a beginner, read help before using an existing class.
Please don't get offended, improve your approach, which should help you.)
—SA