C
C#Elio

✅ EqualityComparer

Hello, anyone know of this code work ? --> EqualityComparer<ICollection<myclass>> .Default.Equals(myclassS, x.myclassS) cause i'm wondering if this will trigger the equals override inside myclass to compare each element or if it will do an equal on the collection to look if they have the same hashcode or something like that
M
MODiX392d ago
thinker227#5176
REPL Result: Success
class MyClass
{
public override bool Equals(object? other)
{
Console.WriteLine("equals");
return other is MyClass;
}
}

List<MyClass> a = new() { new() };
List<MyClass> b = new() { new() };
EqualityComparer<ICollection<MyClass>>.Default.Equals(a, b)
class MyClass
{
public override bool Equals(object? other)
{
Console.WriteLine("equals");
return other is MyClass;
}
}

List<MyClass> a = new() { new() };
List<MyClass> b = new() { new() };
EqualityComparer<ICollection<MyClass>>.Default.Equals(a, b)
Result: bool
False
False
Compile: 774.298ms | Execution: 95.486ms | React with ❌ to remove this embed.
T
Thinker392d ago
It calls List<T>.Equals (in this case) EqualityComparer<T> doesn't do anything special for collections
E
Elio392d ago
So if i want to compare 2 list i should make my own method or can i override the equals methods without creating my own List class ?
T
Thinker392d ago
You can use SequenceEqual from Linq
M
MODiX392d ago
thinker227#5176
REPL Result: Success
new[] { 1, 2, 3 }.SequenceEqual(new[] { 1, 2, 3 })
new[] { 1, 2, 3 }.SequenceEqual(new[] { 1, 2, 3 })
Result: bool
True
True
Compile: 456.640ms | Execution: 48.174ms | React with ❌ to remove this embed.
E
Elio392d ago
😮 i will try right away thanks !
Want results from more Discord servers?
Add your server
More Posts
❔ error attaching script (unity)this error appears when trying to attach the script, does anyone know how to solve it?❔ i have an app that runs well on my pc but not on other pcsi have an app that runs well on my pc but on when i zip it and bring it to another pc the ui is all yield???```cs public IEnumerable<int> A() { for (int i = 0; i <= 10; i += 2) yield return i; } C# Data Table issuehttps://pastebin.com/DSHwSh0M based on this program, I need to set the values of the `Old PS A11Y S❔ Microsoft Graph SDK - Serializing objectsHello, I am currently working with Microsoft Graph API to work with the Planner. My goal is to backu❔ XML deserialise different types into a single listI'm using the build in XML serialisation library (unless it's with .NET framework?), and I current h❔ Access things from different scene in UnityI have a Class Selector scene that has a Class Selector Script component (MonoBehaviour) attached to❔ C# how do I write an If-statement to handle a button?Hi, I wanted some assistance with writing a If-statement that filters out the zones section in my ap❔ Magnetic Links for application?Hey, does someone have an article/tutorial/explanation how I can develop magnetic links for my appli❔ Show values from a list in a datagridview getting source from bindingsourceHello! I have the following problem: I am currently developing a winforms app with a datagridview th❔ Render email content .NET 7 (razor)I have to reinplement email content rendering, because currently its not looking really good, especi❔ GetAxis wont workpublic class Driver : MonoBehaviour { // Start is called before the first frame update const✅ (SOLVED)Help a Beginneri am following CodeMonkeys 11Hr youtube video on coding a game in unity. I have ran into a issue whe❔ Exclude items from linq query if they contain one from an array of substringsI've got a list of strings, that if they appear anywhere in a linq query column i want to exclude th✅ Comprehension questions (LeetCode Binary Search)Like the title says it's about this puzzle https://leetcode.com/problems/binary-search/description/ ❔ How to create a cubic function calculator that also calculates the minimum and maximum value```c Console.WriteLine("Please enter a, b, c, d for the cubic function ax^3+bx^2+cx+d"); ❔ how to listen to the output of a virtual audio device on windows using C#?how to listen to the output of a virtual audio device on windows using C# to save the raw audio stre❔ How to wait for process to completei want to make program opens async but instead of giving 'hard coded' delays but i don't know how to❔ Problem with including C DLL in a C# console app project.So I have this C DLL imported into my console app (.NET 5). I simply cannot get to call it correctly✅ Win Form Event Handlers questionHi, I was just wondering if there is an event handler when the win form is idle that I can then run