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

标签 c# .net-4.0

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

# 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 安装以下内容来修复此问题

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

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

关于c# - 排序字典和列表 <>() 在 VS 2010 中有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58423768/

相关文章:

c# - 注册表项 EditionID 在 WOW6432Node 下有错误的值 - 是故意还是错误?如何绕过?

c# - 使用分部类扩展 WebControl

c# - Visual Studio 2010 未检测到 .NET Framework 4.0

c# - 抵御 System.Collections.Concurrent.ConcurrentDictionary 中的竞争条件

c# - Visual Studio 如何在本地运行 Web 服务?

c# - 如何使用 TcpClient 应对 Nagle 算法?

c# - Entity Framework 4 : where is my load method and IsLoaded property?

ASP.NET 路由导致页面资源无法加载

c# - 在C#.NET4应用程序中在后台处理多个输入

MSBuild:错误 MSB3147:找不到所需文件 'setup.bin'