Comparing 2 custom objects - C#

前端 未结 6 1447
鱼传尺愫
鱼传尺愫 2021-01-05 11:48

I need to write a generic method in the base class that would accept 2 objects as parameters and compares them for equality.

Ex:

public abstract cla         


        
6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-05 12:33

    Yes, you will have to use reflection, because the base class knows nothing about derived classes. But why do you want to implement that function in the base class? Why not in the derived classes?

    Further there is a standard way to do this by overriding Object.GetHashCode() and Object.Equals().

提交回复
热议问题