The Concat method adds strings (or objects) and returns a new string. Using Concat method, you can add two strings, two objects and one string and one object or more combination of these two.
The following source code concatenates two strings.
- string str1 = "ppp";
- string str2 = "ccc";
- string strRes = String.Concat(str1, str2);
- Console.WriteLine(strRes);
The following source code concatenates one string and one object.
- object obj = (object)12;
- strRes = String.Concat(str1, obj);
- Console.WriteLine(strRes);
- string str1 = "ppp";
- string str2 = "ccc";
- string strRes = String.Copy(str1);
- Console.WriteLine("Copy result :" + strRes);
- string str1 = "ppp";
- char[] chrs = new Char[2];
- str1.CopyTo(0, chrs, 0, 2);
- string str1 = "ppp";
- object objClone = str1.Clone();
- Console.WriteLine("Clone :"+objClone.ToString());
- string str1 = "ppp";
- string str2 = "ccc";
- string str3 = "kkk";
- string[] allStr = new String[]{str1, str2, str3};
- string strRes = String.Join(", ", allStr);
- Console.WriteLine("Join Results: "+ strRes);
The output from above codes is shown in below figure


Join the conversation! Your thoughts help the community grow.