String concatenation - CSharp Language Basics

CSharp examples for Language Basics:string

Introduction

The + operator concatenates two strings:

Demo Code

using System;//from   w  w  w.  ja  v  a 2  s .  com
class Test
{
   static void Main(){
      string s = "a" + "b";
      Console.WriteLine (s);
   }
}

Result

One of the operands may be a nonstring value, in which case ToString is called on that value. For example:

Demo Code

using System;//from  w w w .j  av a  2 s. c  om
class Test
{
static void Main(){
     string s = "a" + 5;  // a5

     Console.WriteLine (s);
}
}

Result


Related Tutorials