开发者

comparing 2 objects

开发者 https://www.devze.com 2023-02-22 12:26 出处:网络
I was wondering how you compare two objects for different values. What do i need to research to accomplish this? Is it a comparator and if so could someone point me to a good tutorial?

I was wondering how you compare two objects for different values. What do i need to research to accomplish this? Is it a comparator and if so could someone point me to a good tutorial?

For example i want to see if 2 forms differ via their content (2 contact details form with 2 different sets of contact data, both have the sa开发者_JAVA技巧me getType().Name but have different contents.)

Thanks


If you want to test for equality, then the way to go is have SomeType implement IEquatable<SomeType> and do the comparison in the Equals method (which is what you would call to test for equality, obviously).

If you want to order the values, then the corresponding interface is IComparable<T>.

There are code examples if you follow the links.


You can implement the IComparable interface to allow comparisons between two objects. Documentation here.


You can impliment IComparable on both forms.

http://msdn.microsoft.com/en-us/library/system.icomparable.aspx

This will let you set how these classes are compared.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号