C#: Create a new string using two given strings s1, s2, the format of the new string will be s1s2s2s1
String Format s1s2s2s1
Write a C# Sharp program to create a string using the two given strings s1, s2. The new string format will be s1s2s2s1.
Visual Presentation:

Sample Solution:-
C# Sharp Code:
using System; // Import the System namespace which contains fundamental types and base classes
using System.Collections.Generic; // Import the System.Collections.Generic namespace for collections
using System.Linq; // Import the LINQ namespace for LINQ functionality
using System.Text; // Import the System.Text namespace for string manipulation
using System.Threading.Tasks; // Import the System.Threading.Tasks namespace for asynchronous operations
namespace exercises // Define a namespace called 'exercises'
{
class Program // Define a class named 'Program'
{
static void Main(string[] args) // The entry point of the program
{
// Output the result of test function with two strings as arguments
Console.WriteLine(test("Hi", "Hello")); // Test with strings "Hi" and "Hello"
Console.WriteLine(test("whats", "app")); // Test with strings "whats" and "app"
Console.ReadLine(); // Wait for user input before closing the console window
}
// Function definition of test function that takes two strings 's1' and 's2' and returns a string
public static string test(string s1, string s2)
{
return s1 + s2 + s2 + s1; // Concatenate s1, s2, s2, and s1 together and return the resulting string
}
}
}
Sample Output:
HiHelloHelloHi whatsappappwhats
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C# program to format a string as s2+s1+s1+s2.
- Write a C# program to create a string in the form of s1 + Reverse(s2) + s1.
- Write a C# program to create a string as the concatenation of s1, the middle char of s2, then s1.
- Write a C# program to return a string in the format: uppercase(s1) + s2 + lowercase(s1).
Go to:
PREV : Check Equal Differences in Three Integers.
NEXT : Insert String into Middle of Another.
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.