I have two classess with following properties say: class A and class B
i want to check if any of the objects of class A and class B are equal or nor like
A. name = B.name or A.ID =B.ID or A. Address = B. address
right now i am doing like bool name = A.name.Equals(B.Name)
bool address = A.address.Equals(B.address) like this but is there a cleaner way to do this like a single method to iterate through the objects and verify if any one of the objects do not match their namesake in the other class. thank you
I have two classess with following properties say: class A and class B
i want to check if any of the objects of class A and class B are equal or nor like
A. name = B.name or A.ID =B.ID or A. Address = B. address
right now i am doing like bool name = A.name.Equals(B.Name)
bool address = A.address.Equals(B.address) like this but is there a cleaner way to do this like a single method to iterate through the objects and verify if any one of the objects do not match their namesake in the other class. thank you
There is no getting around doing a comparison. However, you can abstract the logic into the object itself by overriding equals, craft an extension method, or build a static utility method that does the comparison.
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
123 Points
422 Posts
compare objects in two different classes?
Oct 23, 2017 02:12 AM|akpaga22|LINK
Hi Friends,
I have two classess with following properties say: class A and class B
i want to check if any of the objects of class A and class B are equal or nor like
A. name = B.name or A.ID =B.ID or A. Address = B. address
right now i am doing like bool name = A.name.Equals(B.Name)
bool address = A.address.Equals(B.address) like this but is there a cleaner way to do this like a single method to iterate through the objects and verify if any one of the objects do not match their namesake in the other class. thank you
Member
123 Points
422 Posts
Re: compare objects in two different classes?
Oct 23, 2017 06:30 PM|akpaga22|LINK
any help on this please?
All-Star
52101 Points
23237 Posts
Re: compare objects in two different classes?
Oct 23, 2017 06:45 PM|mgebhard|LINK
There is no getting around doing a comparison. However, you can abstract the logic into the object itself by overriding equals, craft an extension method, or build a static utility method that does the comparison.
See the following reference documentation.
https://msdn.microsoft.com/en-us/library/336aedhh(v=vs.100).aspx
Contributor
5290 Points
2307 Posts
Re: compare objects in two different classes?
Oct 24, 2017 10:30 AM|AngelinaJolie|LINK
Hi akpaga22,
The easiest way:
Bests, Angelina Jolie
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.