Use StringBuilder to create string from a large number of records
suggest changepublic string GetCustomerNamesCsv()
{
List<CustomerData> customerDataRecords = GetCustomerData(); // Returns a large number of records, say, 10000+
StringBuilder customerNamesCsv = new StringBuilder();
foreach (CustomerData record in customerDataRecords)
{
customerNamesCsv
.Append(record.LastName)
.Append(',')
.Append(record.FirstName)
.Append(Environment.NewLine);
}
return customerNamesCsv.ToString();
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents