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

  • Home
  • SEARCH
  • 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 8662383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:43:32+00:00 2026-06-12T16:43:32+00:00

I remember long ago reading somewhere that to check a String object against a

  • 0

I remember long ago reading somewhere that to check a String object against a literal (or a constant, etc.) string, a way to skip null check is:

string a;
// do something
if("some literal string".Equals(a))
    Console.WriteLine("equal");

is preferred rather than

string a;
// do something
if(a!=null && a.Equals("some literal string"))
    Console.WriteLine("equal");

to skip checking against null. However cannot find information about it right now; do you have any objections or concerns about the former one?

  • 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-12T16:43:33+00:00Added an answer on June 12, 2026 at 4:43 pm

    You’re probably thinking about Java, where you need to use equals in order to perform a true value equality check for strings; == would just compare references for identity.

    C#, however, has operator overloading – and string overloads == for equality. So it’s fine to write:

    if (text == "target value")
    

    The == operator handles null on either (or both) sides of the comparison:

    • If both sides are null, the result is true
    • If exactly one side is null, the result is false
    • Otherwise, the strings are compared for ordinal equality

    Note, however, that the overload will only be used if the compile-time type of both expressions is string. For example, if you had:

    object o = new String("foo".ToCharArray());
    if (o == "foo")
    

    … then that will compare references instead of using the overloaded operator.

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

Sidebar

Related Questions

I remember reading somewhere (a long time ago) that sprites - or at least
A long time ago, I remember reading a quite strong recommendation from Microsoft against
A long time ago I remember reading that you should always use the smallest
I remember that I've seen this effect long time ago on a website. It
I remember hearing a long time ago that it was considered best practice to
I remember the days (not too long ago, really) when log4net came along with
I remember hearing somewhere that large functions might have higher execution times because of
Long time ago, I was creating a mini ORM using reflection. While reading about
A long time ago I used to program in C for school. I remember
I remember long ago there is option to change color-scheme for source on BitBucket.

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.