Write a C# program to create a new string from a given string where the first and last characters will change their positions

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

Write a C# program to create a new string from a given string where the first and last characters will change their positions

Sample Output:

e3resourcw                                                             
nythoP                                                                 
x

الأجوبة

using System;
using System.Collections.Generic;

public class Exercise16 {
  static void Main(string[] args)
        {
            Console.WriteLine(first_last("w3resource"));
            Console.WriteLine(first_last("Python"));
            Console.WriteLine(first_last("x"));
        }
       public static string first_last(string ustr)
        {
            return ustr.Length > 1
                ? ustr.Substring(ustr.Length - 1) + ustr.Substring(1, ustr.Length - 2) + ustr.Substring(0, 1) : ustr;
        }
}
هل كان المحتوى مفيد؟

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

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