In this source code example, we will demonstrate the usage of String.Concat() method in C# with an example.
The C# Concat() method is used to concatenate multiple string objects. It returns a concatenated string. String Concat() method concatenates the elements of a specified String array.
C# String Concat Method Example
using System;
public class StringDemo
{
public static void Main(string[] args)
{
string s1 = "source";
string s2 = "code";
string s3 = "examples";
Console.WriteLine(string.Concat(s1,s2));
Console.WriteLine(string.Concat( string.Concat(s1, s2), s3));
}
}
Output:
sourcecode
sourcecodeexamples
C# String Concat(String[]) Method Example
The following example demonstrates the use of the Concat method with a String array.
using System;
public class StringDemo
{
public static void Main(string[] args)
{
// Make an array of strings. Note that we have included spaces.
string [] s = { "hello ", "and ", "welcome ", "to ",
"this ", "demo! " };
// Put all the strings together.
Console.WriteLine(string.Concat(s));
// Sort the strings, and put them together.
Array.Sort(s);
Console.WriteLine(string.Concat(s));
}
}
Output:
hello and welcome to this demo!
and demo! hello this to welcome
Related C# String Examples
- C# String Clone Method Example
- C# String Compare Method Example
- C# String CompareTo Method Example
- C# String Concat Method Example
- C# String Contains Method Example
- C# String Copy Method Example
- C# String CopyTo Method Example
- C# String EndsWith Method Example
- C# String Equals Method Example
- C# String GetEnumerator Method Example
- C# String GetHashCode Method Example
- C# String IndexOf Method Example
- C# String Insert Method Example
- C# String Intern Method Example
- C# String IsNullOrEmpty Method Example
- C# String IsNullOrWhiteSpace Method Example
- C# String LastIndexOf Method Example
Comments
Post a Comment