GetHashcode(),Equals(),Isnull(), Isempty() RRS feed

  • Question

  • User1780985398 posted

    I am in a project where the application designer has designed such that all the classes overrides GetHashcode(),Equals(),Isnull(), Isempty() and the operators == and !==. Those functions doesn't seem to be used anywhere and it seems we need to make hundreds of classes in our project.

    Is it really necessary to have those methods as a part of design assuming that it will be useful somewhere as it just increases the coding lines and the time.


    Friday, May 7, 2010 7:06 AM


  • User-837620913 posted

    You only need to override GetHashCode if you override the Equals method.  You typically do this for custom types (classes) so that if you have 2 objects that represent data from a database, if you call Equals you will get the correct result.   Overriding == and != if you have overridden the Equals method is technically a "convenience" but you really should do it to make development with your classes easier.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, May 7, 2010 8:20 AM