Coding Tutorial: C# offers lots of different ways to determine if two objects are equal. Here we discuss the whole range. Source code available at: github.com/JasperKent/Equalit...
Any more of these fundamentals you'd like to know? Just ask. Source code at: github.com/JasperKent/Equality-And-Hashcodes Don't forget to subscribe at ru-vid.com/show-UCqWQzlUDdllnLmtgfSgYTCA And if you liked it, click the 👍.
Just encountered this channel in a recommendation and I haven't looked back since. I've been deep in learning C#/Dotnet for about 18 months now and you seem to have explained so simply almost every little 'hmmm?' moment I've had in the optimal level of detail! Great channel. Thank you so much for taking the time to produce this content.
I've been looking for a video like this for a while that explains why you need to coordinate Equals and GetHashCode. I'm glad I found yours because it explains it perfectly. Thank you. BTW, Amazon quizzes you about hashes until you're hashed out so this is a good primer for their technical interview.
very interesting the information you are showing... not so easy to find it so complete in other channels... but please... declare the variables with "var v = new " to unclutter the code you are showing...
Eh? If the x and y swapped produces the same hashcode then it could change behaviour if you're using hashsets to check if you already have something added to a list for example without using list.contains.
No, because a matching hash only give a higher probability of equality. Whenever hashes match, it should always be confirmed by an exact equality check. That said, a hashing algorithm that produces different results when the values are swapped would be better. Use HashCode.Combine.
Excellent tutorial! A shame C# doesn't easily allow you to use long (rather than int) hash codes by default as that's far less likely to have clashes between objects. Btw, at 23:45 you create a string and get different hash codes on successive runs. However at 11:40, the two strings you created always produced the same hash code, even on following runs. What gives? EDIT: Ah, to answer my own question, the version where the string produces a different hash code on different runs is due to it being under .NET Core instead of .NET Framework (the latter always produces the same hash code). They both work a bit differently it would seem!
@@CodingTutorialsAreGo Doing some research, it appears the reason for Microsoft's change in .NET Core is due to help security (hackers can potentially exploit the code if they know the hashing algorithm with .NET Framework).