Class CsvWriter
Writer for CSV data.
Inheritance
System.Object
CsvWriter
Implements
System.IDisposable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Mars.Common.IO.Csv
Assembly: Mars.IO.dll
Syntax
public sealed class CsvWriter : IDisposable
Examples
The following example shows how to use CsvWriter to write a matrix in .csv format.
The following example shows how to use CsvWriter to write a jagged array in .csv format.
The following example shows how to use CsvWriter to write a DataTable in .csv format.
It is also possible to use CsvWriter to write matrices (or jagged arrays) containing objects with mixed types:
Constructors
| Improve this Doc View SourceCsvWriter(TextWriter, Char)
Initializes a new instance of the CsvWriter class.
Declaration
public CsvWriter(TextWriter writer, char delimiter = ',')
Parameters
Type | Name | Description |
---|---|---|
System.IO.TextWriter | writer | A TextWriter pointing to the CSV file. |
System.Char | delimiter | The field delimiter character to separate values in the CSV file. If set to zero, will use the system's default text separator. Default is '\0' (zero). |
CsvWriter(String, Char)
Initializes a new instance of the CsvWriter class.
Declaration
public CsvWriter(string path, char delimiter = ',')
Parameters
Type | Name | Description |
---|---|---|
System.String | path | The path to the file to be written. |
System.Char | delimiter | The field delimiter character to separate values in the CSV file. If set to zero, will use the system's default text separator. Default is '\0' (zero). |
Properties
| Improve this Doc View SourceComment
Gets or sets the comment character indicating that a line is commented out.
Declaration
public char Comment { get; set; }
Property Value
Type | Description |
---|---|
System.Char | The comment character indicating that a line is commented out. |
Delimiter
Gets or sets the delimiter character separating each field.
Declaration
public char Delimiter { get; set; }
Property Value
Type | Description |
---|---|
System.Char | The delimiter character separating each field. |
Escape
Gets or sets the escape character letting insert quotation characters inside a quoted field.
Declaration
public char Escape { get; set; }
Property Value
Type | Description |
---|---|
System.Char | The escape character letting insert quotation characters inside a quoted field. |
FormatProvider
Gets or sets the format provider to use when converting
data-types to text representations. Default is to use
CultureInfo.InvariantCulture.
Declaration
public IFormatProvider FormatProvider { get; set; }
Property Value
Type | Description |
---|---|
System.IFormatProvider | The format provider. |
Quote
Gets or sets the quotation character wrapping every field.
Declaration
public char Quote { get; set; }
Property Value
Type | Description |
---|---|
System.Char | The quotation character wrapping every field. |
Writer
Gets the writer.
Declaration
public TextWriter Writer { get; }
Property Value
Type | Description |
---|---|
System.IO.TextWriter | The writer. |
Methods
| Improve this Doc View SourceDispose()
Performs application-defined tasks associated with
freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Finalize()
Finalizes an instance of the CsvWriter class.
Declaration
protected void Finalize()
Write(DataTable)
Writes the specified table in a CSV format.
Declaration
public void Write(DataTable table)
Parameters
Type | Name | Description |
---|---|---|
System.Data.DataTable | table | The data table to be written. |
Write<T>(T[,])
Writes the specified matrix in CSV format.
Declaration
public void Write<T>(T[, ] table)
Parameters
Type | Name | Description |
---|---|---|
T[,] | table | The table to be written. |
Type Parameters
Name | Description |
---|---|
T | The matrix data type. |
Write<T>(IEnumerable<T[]>)
Writes the specified matrix in CSV format.
Declaration
public void Write<T>(IEnumerable<T[]> table)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T[]> | table | The table to be written. |
Type Parameters
Name | Description |
---|---|
T | The matrix data type. |
WriteHeaders(DataTable)
Writes the column names of a data table as the headers of the CSV file.
Declaration
public void WriteHeaders(DataTable table)
Parameters
Type | Name | Description |
---|---|---|
System.Data.DataTable | table | A DataTable whose columns names will be written as headers. |
WriteHeaders(String[])
Writes the column names of a data table as the headers of the CSV file.
Declaration
public void WriteHeaders(params string[] columnNames)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | columnNames | A list of column names to use. |
WriteLine<T>(T[], String)
Writes the specified fields in a CSV format.
Declaration
public void WriteLine<T>(T[] fields, string comment)
Parameters
Type | Name | Description |
---|---|---|
T[] | fields | The fields to be written. |
System.String | comment | An optional comment for the line. |
Type Parameters
Name | Description |
---|---|
T |
WriteLine<T>(T[])
Writes the specified fields in a CSV format.
Declaration
public void WriteLine<T>(T[] fields)
Parameters
Type | Name | Description |
---|---|---|
T[] | fields | The fields to be written. |
Type Parameters
Name | Description |
---|---|
T |
Implements
System.IDisposable