CSV Reports
ClassListToCsvString<T>(IEnumerable<T>) Method
Example 



KellermanSoftware.CsvReports Namespace > CsvWriter Class > ClassListToCsvString Method : ClassListToCsvString<T>(IEnumerable<T>) Method
Class type
List of class objects
Create a CSV string from a list of objects. It will output all public properties of the class as columns.
Syntax
Public Overloads Function ClassListToCsvString(Of T As Class)( _
   ByVal list As IEnumerable(Of T) _
) As String
Dim instance As CsvWriter
Dim list As IEnumerable(Of T)
Dim value As String
 
value = instance.ClassListToCsvString(Of T)(list)
public string ClassListToCsvString<T>( 
   IEnumerable<T> list
)
where T: class
public:
String^ ClassListToCsvStringgeneric<typename T>
( 
   IEnumerable<T^>^ list
) 
where T: ref class

Parameters

list
List of class objects

Type Parameters

T
Class type

Return Value

CSV String
Example
//Example Class
public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime BirthDate { get; set; }
}
 
CsvWriter csvWriter = new CsvWriter(); //Trial Mode
//CsvWriter csvWriter = new CsvWriter("place user name here", "place license key here"); //License Mode
 
List<Person> persons = new List<Person>();
Person person1 = new Person();
person1.FirstName = "John";
person1.LastName = "Smith";
person1.BirthDate = DateTime.Now.AddDays(-1);
persons.Add(person1);
 
string results = csvWriter.ClassListToCsvString(persons);
 
Console.WriteLine(results);
'Example Class
Public Class Person
    Public Property FirstName() As String
    Public Property LastName() As String
    Public Property BirthDate() As Date
End Class
 
Dim csvWriter As New CsvWriter() 'Trial Mode
'Dim csvWriter As New CsvWriter("place user name here", "place license key here") 'License Mode
 
Dim persons As New List(Of Person)()
Dim Person person1 = New Person()
person1.FirstName = "John"
person1.LastName = "Smith"
person1.BirthDate = Date.Now.AddDays(-1)
persons.Add(person1)
 
Dim results As String = csvWriter.ClassListToCsvString(persons)
 
Console.WriteLine(results)
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

CsvWriter Class
CsvWriter Members
Overload List