Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7869993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:29:01+00:00 2026-06-03T01:29:01+00:00

Possible Duplicate: C# difference between == and .Equals() For comparing two variables we can

  • 0

Possible Duplicate:
C# difference between == and .Equals()

For comparing two variables we can use == or Equals method. for example,

        string a = new string(new char[] {'a', 'b', 'c', 'd'});
        string b = new string(new char[] {'a', 'b', 'c', 'd'});

        Console.WriteLine (a==b);
        Console.WriteLine (a.Equals(b));

My question is When should I use == and when should I use Equals? Is there any difference between the two?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:29:03+00:00Added an answer on June 3, 2026 at 1:29 am

    == is an operator, which, when not overloaded means “reference equality” for classes (and field-wise equality for structs), but which can be overloaded. A consequence of it being an overload rather than an override is that it is not polymorphic.

    Equals is a virtual method; this makes it polymorphic, but means you need to be careful not to call it on null instances.

    As a rule of thumb:

    • if you know the type of something, and know it has an == overload (most core types such as string, int, float, etc have == meanings), then use ==
    • if you don’t know the type, Equals(a,b) may be recommended, as this avoids the null issue
    • if you really want to check for the same instance (reference equality), consider using ReferenceEquals(a,b), as this will work even if the == is overloaded and Equals overridden
    • when using generics, consider EqualityComparer<T>.Default.Equals(a,b) which avoids the null issue, supports Nullable-of-T, and supports IEquatable-of-T
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: difference between string object and string literal Let's say I have two
Possible Duplicate: Difference between declaring variables before or in loop? Consider the two codes
Possible Duplicate: What is the difference between String.Empty and “” Is equivalent to String.Empty
Possible Duplicate: Difference between OnClick() event and OnClickListener? I'm semi-new to Android development and
Possible Duplicate: difference between throw and throw new Exception() I'm a programmer working on
Possible Duplicate: Differences in string compare methods in C# Is there any difference between
Possible Duplicate: C# difference between == and .Equals() In my daily code routine I
Possible Duplicate: Difference between string and StringBuilder in c# What’s the difference between System.String
Possible Duplicate: Difference between single quote and double quote string in php Hi all
Possible Duplicate: Calculating the Difference Between Two Java Date Instances hi, I have two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.