C# Program to Convert Lowercase Characters by Uppercase and Vice-Versa

«
»

This is a C# Program to obtain the character from the user and convert the case of the character.

Problem Description

This C# Program Obtains the Character from the User and Convert the Case of the Character.

Problem Solution

Here the user enters the character and the uppercase letters are converted to lowercase and vice versa.

Program/Source Code

Here is source code of the C# Program to Obtain the Character from the User and Convert the Case of the Character. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Obtain the Character from the User and Convert 
 * the Case of the Character
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace casechange
{
    class Program
    {
        static void Main(string[] args)
        {
            char a;
            int i;
            Console.WriteLine("Enter the Character : ");
            a = Convert.ToChar(Console.ReadLine());
            i=(int)a;
            if (a >= 65 && a <= 90)
            {
 
                Console.WriteLine("The Character is : {0}", char.ToLower(a));
 
            }
            else if (a >= 97 && a <= 122)
            {
                Console.WriteLine("The Character is : {0}", char.ToUpper(a));
            }
            Console.ReadLine();
        }
    }
Program Explanation

In this C# program, we are reading the character using ‘a’ variable. Nested else if condition statement is used to check the value of ‘a’ variable is greater than or equal to 65 and less than or equal to 90 by using logical AND operator.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement

If the condition is true then execute the statement. Convert the character to lowercase using toLower() function. Otherwise, if the condition is false then execute else if condition statement. Check the value of character string is lower case. If the condition is true then execute the statement. Convert the character to upper case using ToUpper() function.

Runtime Test Cases
 
Enter the Character : a
The Character is : A

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.