Why is [CanBeNull] appended to IEquatable<T>.Equals() of struct? Is it an error?

public struct Student : IEquatable<Student>
{
public int StudentNumber { get; }

public Student(int studentNumber)
{
StudentNumber = studentNumber;
}

public bool Equals([CanBeNull]Student other)
{
return StudentNumber == other.StudentNumber;
}
}

public class Program
{
private void Operation()
{
var student = new Student(1234);
var result = student.Equals(obj: null);
}
}

 

Tags shown in Rider(2021.3.4v) are shown in bold italics.

student.Equals(null) executes Equals() of ValueType. That is, Student's Equals() method cannot be null.

Is it an error to say this in the IDE? Or am I misunderstood?

3 comments
Comment actions Permalink

Hello, what color scheme do you have set up in Preferences | Editor | Color Scheme? What do you see in context actions if Alt-Enter on it? If there is some error or inspection on it then it should show.

0
Comment actions Permalink

@Olga Diakonova

When I press Alt-Enter on the color scheme, nothing happens.

The following screen will appear. What should I do?

0
Comment actions Permalink

It looks like some custom scheme, did you set it up? Do you have the same issue with one of the default themes? You should be able to change settings if unfold the list:

0

Please sign in to leave a comment.