Public record TaggedNumber(int Number, List Tags) Ĭonsole.WriteLine(p1 = p2) // output: FalseĬonsole.WriteLine(p1 = p3) // output: True Public record Point(int X, int Y, string Name) That is, two record operands are equal when both of them are null or corresponding values of all fields and auto-implemented properties are equal. Record types equalityĪvailable in C# 9.0 and later, record types support the = and != operators that by default provide value equality semantics. If a reference type overloads the = operator, use the Object.ReferenceEquals method to check if two references of that type refer to the same object. However, a reference type can overload the = operator. Reference types equalityīy default, two non-record reference-type operands are equal if they refer to the same object: public class ReferenceTypesEqualityĬonsole.WriteLine(a = b) // output: FalseĬonsole.WriteLine(a = c) // output: TrueĪs the example shows, user-defined reference types support the = operator by default. For more information, see the Tuple equality section of the Tuple types article. The = and != operators are supported by C# tuples. To support the = operator, a user-defined struct must overload it. User-defined struct types don't support the = operator by default. Two operands of the same enum type are equal if the corresponding values of the underlying integral type are equal. For more information and examples, see the Double.NaN or Single.NaN reference article. That means that the NaN value is neither greater than, less than, nor equal to any other double (or float) value, including NaN. For the =,, = operators, if any of the operands is not a number ( Double.NaN or Single.NaN), the result of operation is false.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |