int[] array1 = { 1, 2, 3 }; int[] array2 = { 4, 5, 6 }; int[] resultArray = array1.Concat(array2).ToArray(); // Concatenating two arrays using Concat method Console.WriteLine(string.Join(",", resultArray)); // Output: 1,2,3,4,5,6
string string1 = "Hello"; string string2 = "World"; string string3 = "!"; string resultString = string.Concat(string1, " ", string2, string3); // Combining multiple strings into one Console.WriteLine(resultString); // Output: Hello World!In both examples, we used the Concat method to combine the arrays and strings respectively. The Concat method returns an IEnumerable that contains elements from both the input arrays or strings. The Concat method is a part of the System.Linq namespace in .NET. However, you can also use it in non-LINQ scenarios by calling the System.Linq.Enumerable.Concat method directly.