简体   繁体   English

Visual Studio调试器崩溃

[英]Visual Studio debugger crash

So I'm having some weird error in visual studio. 所以我在Visual Studio中遇到一些奇怪的错误。 The debugger crashes (I think). 调试器崩溃(我认为)。 Here is the function where it crashes. 这是它崩溃的功能。 This is for a generic BST in C#, where the == operator was overloaded to add easy comparison between nodes. 这适用于C#中的通用BST,其中==运算符被重载以在节点之间添加简单的比较。

    public static bool operator ==(Node<T> lhs, Node<T> rhs)
    {
        if ((lhs == null) || (rhs == null))
        {
            return false;
        }

        if((lhs.Data).CompareTo(rhs.Data) == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

It crashes at this line: 它在此行崩溃:

if ((lhs == null) || (rhs == null))

Upon debugging, lhs is indeed null, as soon as it starts comparing, it hangs up, then displays this message: 调试后,lhs确实为空,一旦开始比较,它就会挂断,然后显示以下消息:

在此处输入图片说明

Then the debugging session just ends itself. 然后调试会话本身就结束了。

I don't really understand because in order to try to find out the problem with my code, I'm attempting to debug, but then this error happens and the session just ends itself. 我不太了解,因为为了尝试找出我的代码中的问题,我正在尝试调试,但是随后发生此错误,会话本身就结束了。 I've never seen this before. 我以前从未见过。

You are invoking the == operator recursively. 您将递归调用==运算符。 Use if (ReferenceEquals(lhs, null) || ReferenceEquals(rhs, null)) to avoid this. 使用if (ReferenceEquals(lhs, null) || ReferenceEquals(rhs, null))可以避免这种情况。

Alternatively, with C#7 pattern matching: if (lhs is null || rhs is null) 或者,使用C#7模式匹配: if (lhs is null || rhs is null)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM