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 4623978
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:03:54+00:00 2026-05-22T03:03:54+00:00

Possible Duplicates: Using == or Equals for string comparison Are string.Equals() and == operator

  • 0

Possible Duplicates:
Using == or Equals for string comparison
Are string.Equals() and == operator really same?

I learned Java first and one of the few absolutes is that you never use == to compare if two strings are equal, instead there’s the equals method. So when I landed in C# years ago and noticed that objects still had an Equals method, I assumed the rule still applied.

Now I’m going through an ex-coworker’s code and I’m finding snippets like this everywhere:

if (s.Substring(0, s.IndexOf("_")) == "GBCI") {...}

If I recall correctly, == will compare the address between those two results and since the first half is returned by a function, this will fail because the result won’t be the same address as the constant on the right.

Am I holding on to old Java habits? Or is it a good thing that my coworker isn’t around any more?

P.S. Regardless your answer to comparing strings, I do realize the above would be better stated as s.BeginsWith("GBCI"), but that’s something else entirely.

  • 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-05-22T03:03:55+00:00Added an answer on May 22, 2026 at 3:03 am

    In C#, == comparison for strings compares their values instead of their references. See this section of the C# spec for details.

    So using it like that works fine; your coworker was sane and sober.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicates: String comparison and String interning in Java What is the difference between
Possible Duplicates: Benefits of using the conditional ?: (ternary) operator Is the conditional operator
Possible Duplicates: Does facebook fql contain the sql like operator? FaceBook query using FQL
Possible Duplicates: Is there a way to access a javascript variable using a string
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicates: How to check for equals? (0 == i) or (i == 0)
Possible Duplicates: Direct casting vs 'as' operator? Casting: (NewType) vs. Object as NewType What
Possible Duplicates: How to implement a single instance Java application? How do I make
Possible Duplicates: Detect Antivirus on Windows using C# How to detect if a virusscanner
Possible Duplicates: Get method name and type using lambda expression Can I use Expression<Func<T,

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.