Implementing the IEqualityComparer of T interface for object equality with C# .NET

The generic IEqualityComparer of T provides you a way to indicate whether two custom objects are equal. We’ve looked at equality in a number of posts on this blog – see the link below if you’re curious – and IEqualityComparer fulfils a similar purpose though its usage is different.

Equality comparers are most often used to filter out duplicates from a collection.

Consider the following class:

Read more of this post

Advertisements

Implementing the IEquatable of T interface for object equality with C# .NET

In this short post we’ll see a way how to make two custom objects equatable using the generic IEquatable interface. Consider the following object:

public class Person
{
	public int Id { get; set; }
	public string Name { get; set; }
	public int Age { get; set; }
}

The object superclass has an Equals method that we can test as follows:

Read more of this post

Structurally compare two arrays in .NET

In this post we saw how to determine if two arrays are structurally equal in .NET. Two arrays are said to be structurally equal if they contain the same elements in the same order.

Structural equality has a comparison counterpart: IStructuralComparable. It determines if an array comes before or after or is equal to another array based on the elements within it.

Read more of this post

Using the StringComparer class for string equality with C# .NET

In this post we saw how to use the generic IEqualityComparer of T interface to indicate equality for our custom types. If you need a similar comparer for strings then there’s a ready-made static class called StringComparer which can construct string comparers for you.

The StringComparer class provides comparers for the common string comparison scenarios: ordinal, locale specific and invariant culture comparisons. This is a good MSDN article on the differences between these.

Read more of this post

How to check whether two HashSets are equal in C# .NET

Two HashSet objects in C# are equal if they contain the same values regardless of their order in the collection.

Consider the following integer sets:

HashSet<int> intHashSetOne = new HashSet<int>()
{
	1,2,6,5,7,5
};

HashSet<int> intHashSetTwo = new HashSet<int>()
{
	2,2,8,5,9,4
};

HashSet<int> intHashSetThree = new HashSet<int>()
{
	6,7,5,5,2,1
};

Read more of this post

Structurally compare two arrays in .NET

In this post we saw how to determine if two arrays are structurally equal in .NET. Two arrays are said to be structurally equal if they contain the same elements in the same order.

Structural equality has a comparison counterpart: IStructuralComparable. It determines if an array comes before or after or is equal to another array based on the elements within it.

Read more of this post

Using the StringComparer class for string equality with C# .NET

In this post we saw how to use the generic IEqualityComparer of T interface to indicate equality for our custom types. If you need a similar comparer for strings then there’s a ready-made static class called StringComparer which can construct string comparers for you.

The StringComparer class provides comparers for the common string comparison scenarios: ordinal, locale specific and invariant culture comparisons. This is a good MSDN article on the differences between these.

Read more of this post

ultimatemindsettoday

A great WordPress.com site

Elliot Balynn's Blog

A directory of wonderful thoughts

Robin Sedlaczek's Blog

Developer on Microsoft Technologies

HarsH ReaLiTy

A Good Blog is Hard to Find

Softwarearchitektur in der Praxis

Wissenswertes zu Webentwicklung, Domain-Driven Design und Microservices

the software architecture

thoughts, ideas, diagrams,enterprise code, design pattern , solution designs

Technology Talks

on Microsoft technologies, Web, Android and others

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

Anything around ASP.NET MVC,WEB API, WCF, Entity Framework & AngularJS

Cyber Matters

Bite-size insight on Cyber Security for the not too technical.

Guru N Guns's

OneSolution To dOTnET.

Johnny Zraiby

Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

%d bloggers like this: