String Concatenation()

Part 25 String Concatenation()

Concat() method is used to concatenate multiple string objects. It concatenated string. There are many overloaded methods of Concat()

public static string Concat(String, String)  
public static string Concat(IEnumerable<String>)  
public static string Concat(Object)  
public static string Concat(Object, Object)  
public static string Concat(Object, Object, Object)  
public static string Concat(Object, Object, Object, Object)  
public static string Concat(params Object[])  
public static string Concat(String, String, String)  
public static string Concat(String, String, String,?String)  
public static string Concat(params String[])  
[ComVisibleAttribute(false)]  
public static string Concat<T>(IEnumerable<T>)  

Example 1:


class Concate

{
  public static void main(string[] args)
  {
      string fname = "chandan";
      string lname = "pandey";
      string str;
      str = String.Concat(strA, strB);
      Console.WriteLine("Concatenated string is: {0}", str);
      Console.ReadLine();
  }
}
Output:
Concate string is chandan pandey

Example 2 :

which is created from the concatenation of three strings.

class Concate

{
  public static void main(string[] args)
  {
      string  SubName ="My Name is";
      string fname = "chandan";
      string lname = "pandey";
      string str;
      str = String.Concat (SubName , strA, strB);
      Console.WriteLine("Concatenated string is: {0}", str);
      Console.ReadLine();
  }
}

Output:

My Name is chandan pandey

Concatenates The Elements Of a Specified String Array.


class Program

{
      public static void main(string[] args)
      {
                string[] strA = { "Hey, ", "This ", "is ", "C# ", "Tutorial." };
                // print elements of array   
                foreach (string elements in strA)
                {
                    Console.WriteLine("Elements of strA array : {0}", elements);
                }
                // into single string 
                // using Concat(string[]) Method  
                Console.WriteLine("After Concatenation: {0}", string.Concat(strA));
                Console.ReadLine();
            }
}


Example :
class Program
{
      public static void main(string[] args)
      {
var list = new List<string>(); list.Add("cat"); list.Add("dog"); list.Add("perls"); // Concat the list. string concat = string.Concat(list); Console.WriteLine(concat); // Join the list. string join = string.Join("", list); Console.WriteLine(join);       } 
}

Example :

class Program
{
      public static void main(string[] args)
      {
object obj = "chandan";
object obj1 = "pandey"; // Concat the list. string concat = string.Concat(obj , obj1); Console.WriteLine(concat); Console.WriteLine(join);       } 
}


please tell us .if you satisfied or need more any topic  keep responds your responds motivate me and i made tutorial as soon as possible.