Write a C# Sharp program to reverse the case (upper->lower, lower->upper) of all the characters of given string

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

Write a C# Sharp program to reverse the case (upper->lower, lower->upper) of all the characters of given string. 

Expected Output :

Original string: PHP
After reversing the case of all characters of the said string: php

Original string: JavaScript
After reversing the case of all characters of the said string: jAVAsCRIPT

Original string: Python 3.0
After reversing the case of all characters of the said string: pYTHON 3.0

الأجوبة

using System;
using System.Linq;
namespace exercises
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Original string: PHP");
            Console.WriteLine("After reversing the case of all characters of the said string: " + test("PHP"));
            Console.WriteLine("\nOriginal string: JavaScript");
            Console.WriteLine("After reversing the case of all characters of the said string: " + test("JavaScript"));
            Console.WriteLine("\nOriginal string: Python 3.0");
            Console.WriteLine("After reversing the case of all characters of the said string: " + test("Python 3.0"));
        }
        public static string test(string text)
        {
            return string.Concat(text.Select(x => char.IsUpper(x) ? char.ToLower(x) : char.ToUpper(x)));
        }
    }
}
هل كان المحتوى مفيد؟

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

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