Languages
[Edit]
EN

C# / .NET - static Equals() vs non-static Equals()

7 points
Created by:
Wade
562

In this short article, we would like to explain what is difference between static Equals() vs non-static Equals() in C#.

Usage examples

Edit

1. Static Equals() can be accessed using:

Edit

Syntax:

2. Non-static Equals() can be accessed using:

Edit

Syntax:

 

Difference explaination

Edit

Static Equals() should be used when some of the compared objects may be null - it was created to prevent against NullReferenceException occurrences. Non-static Equals() method is called when some argument is not null.

If we would like to propose how public static bool Equals(object? objA, object? objB) method may be implemented, we could use:

 

References

Edit
  1. Object.Equals Method - Microsoft Docs 

Alternative titles

  1. C# / .NET - static Equals() vs not static Equals()
  2. C# / .NET - object.Equals() vs myObject.Equals()
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join