w3resource

C#: Create a new string using two given strings s1, s2, the format of the new string will be s1s2s2s1


C# Sharp Basic Algorithm: Exercise-60 with Solution

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:

C# Sharp: Basic Algorithm Exercises - Create a new string using two given strings s1, s2, the format of the new string will be s1s2s2s1.

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:

C# Sharp: Flowchart: Create a new string using two given strings s1, s2, the format of the new string will be s1s2s2s1.

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a C# Sharp program to check three given integers (small, medium and large) and return true if the difference between small and medium and the difference between medium and large is same.
Next: Write a C# Sharp program to insert a given string into middle of the another given string of length 4.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/csharp-exercises/basic-algo/csharp-basic-algorithm-exercises-60.php