Getting “Tuple element name is inferred. Please use language version 7.1 or greater to access an element by its inferred name.”

六眼飞鱼酱① 提交于 2019-12-08 14:25:59

问题


We have the following code that has been working fine in our UWP app until today after we updated Visual Studio 2017 to the latest 15.3.

private void Test()
{
    var groups = new List<(Guid key, IList<(string, bool)> items)>();

    var items = new List<(string, bool)>
    {
        ("a", true),
        ("b", false),
        ("c", false)
    };
    var group = (Guid.NewGuid(), items);

    groups.Add(group);
}

There is no error message but this in the output window

Tuple element name 'items' is inferred. Please use language version 7.1 or greater to access an element by its inferred name.

Any idea why and how to fix this?


回答1:


Project->Properties->Build->Advanced->Language Version->C# latest Minor Version




回答2:


This a confirmed bug, introduced in 15.3. The fix will ship as part of a servicing release (15.3.2).

The issue is tracked at https://github.com/dotnet/roslyn/issues/21518




回答3:


Looks like this is a breaking change in C# 7.1. (as pointed out by @JulienCouvreur, this is actually a bug, but the workaround below should still work though).


Workaround

Try giving a name (e.g. use the same name items from IList<(string, bool)> items to be consistent) explicitly to items (i.e. the list instance).

var group = (Guid.NewGuid(), items: items);


来源:https://stackoverflow.com/questions/45684409/getting-tuple-element-name-is-inferred-please-use-language-version-7-1-or-grea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!