Write a C# Sharp program to create a new string which is 4 copies of the 2 front characters of a given string. If the given string length is less than 2 return the original string

  • برمجة سي شارب
  • برمجة

Write a C# Sharp program to create a new string which is 4 copies of the 2 front characters of a given string. If the given string length is less than 2 return the original string

Sample Output:

C C C C 
JSJSJSJS
a

الأجوبة

using System;
namespace exercises
{
  class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(test("C Sharp"));
            Console.WriteLine(test("JS"));
            Console.WriteLine(test("a"));
            Console.ReadLine();
        }
        public static string test(string str)
        {
            return str.Length < 2 ? str : str.Substring(0, 2) + str.Substring(0, 2) + str.Substring(0, 2)  + str.Substring(0, 2);
        }
    }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...