I have a code , i get it from my question from stack overflow
# Read data
var data = new SortedDictionary<(string id, string idr, string email),
List<(string reference, decimal amount)>>();
using (var input = File.OpenText("input.txt"))
{
List<(string reference, decimal amount)> currentInvoice = null;
for (var line = input.ReadLine(); line != null; line = input.ReadLine())
{
var fields = line.Split(new char[] { '@' }, 6);
switch (fields.Length)
{
case 2:
// Sanitize input
if (fields[0] != "INV")
{
throw new Exception("Unknown record type.");
}
if (currentInvoice == null)
{
throw new Exception("Invoice without context.");
}
// Parse
var invoiceEntry = fields[1].Split(new char[] { ' ' },
StringSplitOptions.RemoveEmptyEntries);
if (invoiceEntry.Length == 2)
{
decimal amount;
if (decimal.TryParse(invoiceEntry[1],
NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands,
CultureInfo.InvariantCulture,
out amount))
{
currentInvoice.Add((invoiceEntry[0], amount));
}
}
break;
case 6:
var currentContext = (id: fields[0], idr: fields[2], email: fields[5]);
if (!data.TryGetValue(currentContext, out currentInvoice))
{
currentInvoice = new List<(string reference, decimal amount)>();
data.Add(currentContext, currentInvoice);
}
break;
default:
throw new Exception("Unknown record.");
}
}
}
SortedDictionary can't be used it says
' using
system.collection.generic.sorteddictionary<TKey,TValue>
requires 2 agruments '
the List<(string reference, decimal amount)> currentInvoice = null ;
has an error too , it says
'Only assignment,call,increment, decrement, new object expression can be used as a statement'
how to fix this?