-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLinqOnCsvExample.cs
44 lines (36 loc) · 1.08 KB
/
LinqOnCsvExample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using FolkerKinzel.CsvTools;
namespace Examples;
internal static class LinqOnCsvExample
{
public static void LinqOnCsv(string filePath)
{
object?[][] customers =
[
["Customer", "PhoneNumbers", "Sales"],
["Detlef", null, 3.85m],
["Susi", """
0177-4711,
123-4567
""", 39_457.26m],
["Gabi", "08-15", 28.70m]
];
customers.SaveCsv(filePath);
Console.WriteLine(File.ReadAllText(filePath));
using CsvReader csv = Csv.OpenRead(filePath);
Console.WriteLine();
Console.WriteLine("What phone numbers does Susi have?:");
Console.WriteLine(
csv.FirstOrDefault(x => x["Customer"].Span.Equals("Susi", StringComparison.Ordinal))?["PhoneNumbers"]);
}
}
/*
Console Output:
Customer,PhoneNumbers,Sales
Detlef,,3.85
Susi,"0177-4711,
123-4567",39457.26
Gabi,08-15,28.70
What phone numbers does Susi have?:
0177-4711,
123-4567
*/