I am creating 100s of class instances inside a loop based on some conditions. I try to add all the instances to a List<string> to save it as a csv file. Is there a better option to save instances properties to a csv file.
public class Car
{
public int ID { get; set; }
public double Price { get; set; }
public double Weight { get; set; }
// A Method like this ? is it right way ??
public string PropertiesCSV(Car model )
{
return $"{model.ID}, {model.Price},{model.Weight},";
}
}
public class Inventory
{
// I want to add all the instance properties (ID, Price, Weight) to this list
public static List<string> CSV { get; set; } = new List<string>();
// This method to save the List<string> to a csv file
public void SaveCSV()
{
}
}