1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public static void CreatingCsvFiles(string filename,List<Personne> employes)
{
string filePath =filename + ".csv";
if (!File.Exists(filePath))
{
File.Create(filePath).Close();
}
string delimiter = ";";
List<string> output = new List<string>();
// On itère sur chaque élément de la liste.
foreach (var item in employes)
{
output.Add(item.Nom + " " + item.Age.ToString());
}
int length = output.Count;
StringBuilder sb = new StringBuilder();
for (int index = 0; index < length; index++)
sb.AppendLine(string.Join(delimiter, output[index]));
File.AppendAllText(filePath, sb.ToString());
} |
Partager