c# - string = string + int: What's behind the scenes? -


You can add a string in C # and say, an integer:

  string Sth = "something" + 0;  

My questions are:

  1. By assuming the fact that you can add a string and an integer, the cables like C # Does not allow it to start:

      string sth = 0; // Error: The source type 'int' can not be changed to target type 'string'  
  2. How the C # # forms of string Is it 0.ToString () or (string) 0 or something else?

  3. How to get the answer to the last question?
  4. To make this call, such as:

      String sth = String.Concat ("some", 0);  

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

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

    Public Static String Context (object arg0, object arg1) {if (arg0 == null) {arg0 = String.Empty; } If (arg1 == faucet) {arg1 = String.Empty; } Return concat (arg0.ToString (), arg1.ToString ()); }

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


    To find it, , or Reflector (no optimizer in IL or C #) to see if the + line is compiled for whom.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -