Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用Equals会抛空异常 #13

Open
jaemok0421 opened this issue Sep 27, 2023 · 0 comments
Open

使用Equals会抛空异常 #13

jaemok0421 opened this issue Sep 27, 2023 · 0 comments

Comments

@jaemok0421
Copy link

jaemok0421 commented Sep 27, 2023

rt,zstring类对象在调用Equals与非空对象比较时会抛空。看起来是由于Equals内会将obj转为zstring类并进行非空判定,但重写的!=运算符号直接尝试获取left与right的value导致的

` public override bool Equals(object obj)
{
if (obj == null)
return ReferenceEquals(this, null);

        var gstr = obj as zstring;
        if (gstr != null)
            return gstr._value == this._value;

        var str = obj as string;
        if (str != null)
            return str == this._value;

        return false;
    }`

public static bool operator !=(zstring left, zstring right) { return !(left._value == right._value); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant