concatenate string c# code example

Example 1: c# String.Concat()

string first = "hello_";
string second = "world";
/* Unite multiple strings to one new string*/

string third = String.Concat(first, second);
// string third will be now "hello_world"

Example 2: how add strings together

//Java
String firstName = "BarackObama";
String lastName = " Care";
//First way
System.out.println(firstName + lastName);
//Second way
String name = firstName + lastName;
System.out.println(name);
//Third way
System.out.println("BarackObama" + " Care");

Example 3: c# string concatenation

string userName = "<Type your name here>";
string dateString = DateTime.Today.ToShortDateString();

// Use the + and += operators for one-time concatenations.
string str = "Hello " + userName + ". Today is " + dateString + ".";
System.Console.WriteLine(str);

str += " How are you today?";
System.Console.WriteLine(str);

Example 4: c# Add or Concatenate Strings In C#

string str1 = "ppp";  
string strRes = str1.Insert(2, "bbb");  
Console.WriteLine(strRes.ToString());

Tags:

Java Example