Q:

Write C# Program to check whether a character is alphabet, digit or special character

0

Write C# Program to check whether a character is alphabet, digit or special character

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..

using System;
 
public class charpexercise
{
    static void Main(string[] args)
    {
        char ch;
 
        Console.WriteLine("Enter any character: ");
        ch = Convert.ToChar(Console.ReadLine());
 
        // Alphabet checking condition
        if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
        {
            Console.WriteLine(ch + "is an Alphabet. ");            
        }
        else if (ch >= '0' && ch <= '9')
        {         
            Console.WriteLine(ch + "is a Digit. ");
        }
        else
        {
            Console.WriteLine(ch + "is a Special character.. ");            
        } 
 
        Console.ReadLine();
    }
}

Result:

Enter any character: 

$

$is a Special character..

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write C# Program to accept two integers and check ... >>
<< Write C# Program to check entered character vowel ...