排序字典和列表 <>() 在 VS 2010 中有错误

Sorted Dictionary and List<>() has an error in VS 2010

我有一个代码,我从我的堆栈溢出问题中得到它

# 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 不能使用它说

' using system.collection.generic.sorteddictionary<TKey,TValue> requires 2 agruments '

List<(string reference, decimal amount)> currentInvoice = null ; 也有错误,它说

'Only assignment,call,increment, decrement, new object expression can be used as a statement'

如何解决这个问题?

对于 Visual Studio 的旧版本,您 可以通过从 nuget[= 安装以下内容来修复 这个问题12=]

注意 : 注意依赖关系,你可能需要安装支持目标框架的旧版本

还应注意,如果您使用的是 VS 2010,是时候告诉您的 bosses/managers 升级或使用社区版本了。