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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:36:55+00:00 2026-05-16T02:36:55+00:00

In C# you can implicitly concatenate a string and let’s say, an integer: string

  • 0

In C# you can implicitly concatenate a string and let’s say, an integer:

string sth = "something" + 0;

My questions are:

  1. Why, by assuming the fact that you can implicitly concatenate a string and an int, C# disallows initializing strings like this:

    string sth = 0; // Error: Cannot convert source type 'int' to target type 'string'
    
  2. How C# casts 0 as string. Is it 0.ToString() or (string)0 or something else?

  3. How to find an answer of the previous question?
  • 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-16T02:36:56+00:00Added an answer on May 16, 2026 at 2:36 am

    It compiles to a call to String.Concat(object, object), like this:

    string sth = String.Concat("something", 0);
    

    (Note that this particular line will actually be optimized away by the compiler)

    This method is defined as follows: (Taken from the .Net Reference Source)

        public static String Concat(Object arg0, Object arg1) {
            if (arg0==null) {
                arg0 = String.Empty; 
            }
    
            if (arg1==null) { 
                arg1 = String.Empty;
            } 
            return Concat(arg0.ToString(), arg1.ToString());
        }
    

    (This calls String.Concat(string, string))


    To discover this, you can use ildasm, or Reflector (in IL or in C# with no optimizations) to see what the + line compiles to.

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

Sidebar

Related Questions

If I can implicitly cast an integer value to a double, like: int a
I can call Get<int>(Stat); or Get<string>(Name); But when compiling I get: Cannot implicitly convert
Possible Duplicate: IEnumerable.Cast<> One can implicitly convert from int to double. Why does Specified
According to this page you can implicitly convert shared_ptr<Foo> to shared_ptr<const Foo> . That
I am aware that in C you can't implicitly convert, for instance, char** to
I know that using generic in an assignment, a method can implicitly know the
In the sample code below, it shows that boost::tuple can be created implicitly from
Is there a way that one can implicitly declare top-level variables as global for
With Linq, the range variable (e) can be implicitly typed from the array/collection (emps)
I receive TypeError: Can't convert 'float' object to str implicitly while using Gambler.pot +=

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.