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


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..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2.  
  3. public class charpexercise
  4. {
  5. static void Main(string[] args)
  6. {
  7. char ch;
  8.  
  9. Console.WriteLine("Enter any character: ");
  10. ch = Convert.ToChar(Console.ReadLine());
  11.  
  12. // Alphabet checking condition
  13. if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
  14. {
  15. Console.WriteLine(ch + "is an Alphabet. ");
  16. }
  17. else if (ch >= '0' && ch <= '9')
  18. {
  19. Console.WriteLine(ch + "is a Digit. ");
  20. }
  21. else
  22. {
  23. Console.WriteLine(ch + "is a Special character.. ");
  24. }
  25.  
  26. Console.ReadLine();
  27. }
  28. }

Result

C# language techstudy.org

     





Related Topics




Popular Posts