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

Introduction

Write C# Program to check whether a character is alphabet, digit or special character. 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

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

Leave a Comment

x