- Concat(String, String, String, String)
- Concat(Object, Object, Object, Object)
- Concat(Object, Object, Object)
- Concat(String, String)
- Concat(String, String, String)
- Concat(String[])
- Concat(Object[])
- Concat(Object)
- Concat(Object, Object)
- Concat(IEnumerable<String>)
- Concat<T>(IEnumerable<T>)
1. Concat(String, String, String, String)
This method is used to concatenate four different string into a single string. You can also use Concatenation operator(+)to concatenate strings.
Note: If an array contains a null object, then the Empty string is used in place of a null object.
Syntax:
public static string Concat (string strA, string strB, string strC, string strD);
Parameters:
strA: First string to concatenate.
strB: Second string to concatenate.
strC: Third string to concatenate.
strD: Fourth string to concatenate.
The type of all these parameters is System.String.
Return Value: The return type of this method is System.String. This method returns a string which is created from the concatenation of four strings, i.e. strA, strB, strC, and strD.
Example:
using System;
class GFG {
static public void Main()
{
string strA = "Welcome " ;
string strB = "to " ;
string strC = "GFG " ;
string strD = "Portal." ;
string str;
Console.WriteLine( "String A is: {0}" , strA);
Console.WriteLine( "String B is: {0}" , strB);
Console.WriteLine( "String C is: {0}" , strC);
Console.WriteLine( "String D is: {0}" , strD);
str = String.Concat(strA, strB, strC, strD);
Console.WriteLine( "Concatenated string is: {0}" , str);
}
}
|
Output:
String A is: Welcome
String B is: to
String C is: GFG
String D is: Portal.
Concatenated string is: Welcome to GFG Portal.
2. Concat(Object, Object, Object, Object)
This method is used to concatenate the string representations of four specified objects and any objects specified in an optional variable length parameter list.
Note: If a null argument is present in this method then String.Empty is used in place of a null argument.
Syntax:
public static string Concat (object argA, object argB, object argC, object argD);
Parameters:
argA: First object to concatenate.
argB: Second object to concatenate.
argC: Third object to concatenate.
argD: Fourth object to concatenate.
Return Value: The return type of this method is System.String. It returns the concatenated string which is the representation of each value present in the parameter list.
Example:
using System;
class GFG {
public static void Main()
{
string strA = "Hello! " ;
object ob = strA;
Object[] objs = new Object[] { "Black" , " Blue" };
Console.WriteLine( "Concatenate four objects: {0}" ,
String.Concat(ob, ob, ob, ob));
Console.WriteLine( "Concatenate two element object array: {0}" ,
String.Concat(objs));
}
}
|
Output:
Concatenate four objects: Hello! Hello! Hello! Hello!
Concatenate two element object array: Black Blue
3. Concat(Object, Object, Object)
This method is used to concatenates the string representations of three specified objects. If a null argument is present in this method then String.Empty is used in place of null argument.
Syntax:
public static string Concat (object argA, object argB, object argC);
Note: The method concatenates argA, argB, and argC by calling the parameterless ToString method of each object and it does not add any delimiters.
Parameters:
argA: First object to concatenate.
argB: Second object to concatenate.
argC: Third object to concatenate.
Return Value: The return type of this method is System.String. This method returns a concatenated string, which is the representation of each value present in the parameter list.
Example:
using System;
class GFG {
public static void Main()
{
string strA = "GFG " ;
object ob = strA;
Console.WriteLine( "Concatenate three objects : {0}" ,
String.Concat(ob, ob, ob));
}
}
|
Output:
Concatenate three objects : GFG GFG GFG
Next : Set 2, Set 3
Reference: https://docs.microsoft.com/en-us/dotnet/api/system.string.concat?view=netframework-4.7.2
Last Updated :
01 Feb, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...