error-defines operator == or operator != but does not override Object.GetHashCode()
-
hi I am having strange problem in my class file.I am adding collection to support vector struct but it gives me these two warnings
C:\Visual Studio Projects\Cons12\EntryPoint.cs(24): 'Cons12.VectorClass.Vector' defines operator == or operator != but does not override Object.Equals(object o))
C:\Visual Studio Projects\Cons12\EntryPoint.cs(24): 'Cons12.VectorClass.Vector' defines operator == or operator != but does not override Object.GetHashCode()I am unable to understand what it is and how it can be resolved Can anyone explain me how and why it happens the above error thanks in advance sasi
-
hi I am having strange problem in my class file.I am adding collection to support vector struct but it gives me these two warnings
C:\Visual Studio Projects\Cons12\EntryPoint.cs(24): 'Cons12.VectorClass.Vector' defines operator == or operator != but does not override Object.Equals(object o))
C:\Visual Studio Projects\Cons12\EntryPoint.cs(24): 'Cons12.VectorClass.Vector' defines operator == or operator != but does not override Object.GetHashCode()I am unable to understand what it is and how it can be resolved Can anyone explain me how and why it happens the above error thanks in advance sasi
-
Did you used the overwrite word in the definition of the new operator? ------------------------------ A bug in a Microsoft Product? No! It's not a bug it's an undocumented feature!
-
hi I am having strange problem in my class file.I am adding collection to support vector struct but it gives me these two warnings
C:\Visual Studio Projects\Cons12\EntryPoint.cs(24): 'Cons12.VectorClass.Vector' defines operator == or operator != but does not override Object.Equals(object o))
C:\Visual Studio Projects\Cons12\EntryPoint.cs(24): 'Cons12.VectorClass.Vector' defines operator == or operator != but does not override Object.GetHashCode()I am unable to understand what it is and how it can be resolved Can anyone explain me how and why it happens the above error thanks in advance sasi
These warnings are telling you that because you have overriden the == and != operator there are 2 further methods inherited from Object that you should override. Equals - returns true if the object passed into the obj parameter should be considered equal the current object GetHashCode - returns an int used in hashing algorithms. Objects that return true from Equals should return the same HashCode from this method. You can override these methods in your object by using the override keyword.
-
hi I am having strange problem in my class file.I am adding collection to support vector struct but it gives me these two warnings
C:\Visual Studio Projects\Cons12\EntryPoint.cs(24): 'Cons12.VectorClass.Vector' defines operator == or operator != but does not override Object.Equals(object o))
C:\Visual Studio Projects\Cons12\EntryPoint.cs(24): 'Cons12.VectorClass.Vector' defines operator == or operator != but does not override Object.GetHashCode()I am unable to understand what it is and how it can be resolved Can anyone explain me how and why it happens the above error thanks in advance sasi
Are you sure that they are errors, not warnings? The compiler says that you have created a class that will behave erratically. The Equals method should give the same result as the equality operator, so if you override one of them, you should override the other. If you compare the object to something, it will first look for a specific equality operator for the data type, and if none exists, it uses the Equals method. If you have overridden only the equality operator but not the Equals method, the comparison will work differently depending on what you compare it to. The GetHashCode method is used among other things when you put an object in certain collections. If the GetHashCode methods isn't based on the same data as the equality operator, the object won't work correctly in the collection. --- b { font-weight: normal; }
-
hi I am having strange problem in my class file.I am adding collection to support vector struct but it gives me these two warnings
C:\Visual Studio Projects\Cons12\EntryPoint.cs(24): 'Cons12.VectorClass.Vector' defines operator == or operator != but does not override Object.Equals(object o))
C:\Visual Studio Projects\Cons12\EntryPoint.cs(24): 'Cons12.VectorClass.Vector' defines operator == or operator != but does not override Object.GetHashCode()I am unable to understand what it is and how it can be resolved Can anyone explain me how and why it happens the above error thanks in advance sasi
It must be a warning ! simply ignore it or add Equals, GetHash function