Click here to Skip to main content
15,903,385 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
NxtRecord record = obj as NxtRecord;
if(!this.m_record.Equals(record.m_record))
return false;
else
return true;

Note : m_record is class and record.m_record is struct and I am using VS2008
Posted

"Null dereference" is absurd. Null is not dereferenced, it's null.

There is one thing you need to understand: as System.Object.Equals can be overridden (https://msdn.microsoft.com/en-us/library/bsc2ak47%28v=vs.110%29.aspx[^]), a really reliable way to compare object with null is using System.Object.ReferenceEquals:
https://msdn.microsoft.com/en-us/library/system.object.referenceequals%28v=vs.110%29.aspx[^].

However, this is usually the issue when you redefine object equivalence for your type and need to use comparison with null in implementation of equality/identity (if you fail to do so, you can face unlimited recursion), or deal with a type which equality is already redefined on some unusual way. In an ordinary situation, simple MyObject == null comparison works just fine.

See also: https://msdn.microsoft.com/en-US/library/ms173147%28v=vs.80%29.aspx[^].

—SA
 
Share this answer
 
When the other object is null, it is obviously not equal to this object. Consequently, start with
C#
if (record == null)
    return false;

... and make the rest better readable with
C#
else
    return this.m_record.Equals(record.m_record);
 
Share this answer
 
Comments
Member 11770170 12-Oct-15 2:36am    
Solution 2 is also not working, because am scanning code using HPFortify tool

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900