gpt4 book ai didi

C#意外元组使用和元组相等使用,需要备选(初学者)

转载 作者:行者123 更新时间:2023-11-30 21:26:27 25 4
gpt4 key购买 nike

我正在尝试完成 leetcode 的问题 #1266 ( https://leetcode.com/problems/minimum-time-visiting-all-points/ )。

我的解决方案在 Visual Studio 上工作很好,但是当我将它提交到 leetcode 时,我遇到了一个编译时错误:

Line 19: Char 12: error CS8320: Feature 'tuple equality' is not available in C# 7.2. Please use language version 7.3 or greater. (in Solution.cs)

            (int, int) current = test[0];
(int, int) target = test.Last();

for (int i = 1; i < test.Count; i++)
{
target = test[i];

while (current != target) <<<<<<<<<<<<< ERROR LINE according to leetcode

我相信我的 VS2019 是最新的(我现在更新到最新版本:16.3.9 --> 16.4.0)所以我我不确定我还需要做什么。

我的问题是:有没有我可以使用的简单替代方案,或者我应该继续前进? (就我而言,我的解决方案通过了 - 它完成了给定的测试用例。)

感谢您的宝贵时间和帮助。

附言抱歉,如果您需要我的更多代码,我会在需要时将其包括在内。它有点老套而且很长,哈哈。

最佳答案

您可以比较元组的属性,而不是比较元组:

 ...
// tuples current and target are not equal if either Item1 or Item2 are not equal
while (current.Item1 != target.Item1 || current.Item2 != target.Item2)
...

您可能需要明确的 Tuple<int, int>语法也是:

 Tuple<int, int> current = test[0];
Tuple<int, int> target = test.Last();

关于C#意外元组使用和元组相等使用,需要备选(初学者),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59191710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com