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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:04:13+00:00 2026-06-04T19:04:13+00:00

This is valid C# code var bob = abc + null + null +

  • 0

This is valid C# code

var bob = "abc" + null + null + null + "123";  // abc123

This is not valid C# code

var wtf = null.ToString(); // compiler error

Why is the first statement valid?

  • 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-04T19:04:14+00:00Added an answer on June 4, 2026 at 7:04 pm

    The reason for first one working:

    From MSDN:

    In string concatenation operations,the C# compiler treats a null string the same as an empty string, but it does not convert the value of the original null string.

    More information on the + binary operator:

    The binary + operator performs string concatenation when one or both operands are of type string.

    If an operand of string concatenation is null, an empty string is substituted. Otherwise, any non-string argument is converted to its string representation by invoking the virtual ToString method inherited from type object.

    If ToString returns null, an empty string is substituted.

    The reason of the error in second is:

    null (C# Reference) – The null keyword is a literal that represents a null reference, one that does not refer to any object. null is the default value of reference-type variables.

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

Sidebar

Related Questions

Unfortunately, this may not be a valid Code-Golf question as it is likely Javascript
I'm porting some code from Python 2 to 3. This is valid code in
Is this code valid C: fputc(*(Checking 7 bytes before this string-7), stdout); Is there
This isn't valid code: public class MyClass { private static boolean yesNo = false;
Title is most of the question, what allows this to be valid code? Is
Is it possible to make this line of code valid? description, content, state, city,
Is this code possible? switch (rule) { case 'email' || 'valid_email': valid = this.validate_email(field);
Is this valid C++ (e.g. not invoking UB) and does it achieve what I
Is this a valid function pointer code below, In views , def change(request): dict={}
Javascript objects can be used as maps. The following all is valid code: var

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.