string.concat c# | How to concatenate multiple strings C#

string.concat c#

 

How to concatenate multiple strings C#

 

string userName = "Usingcsharp";
string date = DateTime.Today.ToShortDateString();

// Use string interpolation to concatenate strings.
string str = $"Hello {userName}. Today is {date}.";
System.Console.WriteLine(str);

str = $"{str} How are you?";
System.Console.WriteLine(str);

 

using System; 
  
public class usingcsharp{ 
      
    // Main Method 
    static public void Main() 
    { 
        string str1 = "Hello! "; 
        string str2 = "world"; 
        string str; 
  
        // print all strings 
        Console.WriteLine("String 1 is: {0}", str1); 
        Console.WriteLine("String 2 is: {0}", str2); 
  
        // Concatenate two different strings 
        
        str = String.Concat(str1, str2); 
  
        Console.WriteLine("Concatenated string is: {0}", str); 
    } 
} 

 

Output

String 1 is: Hello! 
String 2 is: world
Concatenated string is: Hello! wordl
 

2021-10-03