How to determine the type of a Character in C#?

Below code show how to determine the type of a character in CSharp/C# –

[csharp]
using System;

namespace kodehelp.csharp.system
{
public class CharType
{
public static void Main(string[] args)
{
char c = args[0];

if (Char.IsDigit(c))
{
Console.WriteLine("Char " + c + " is digit");
}
else if (Char.IsNumber(c))
{
Console.WriteLine("Char " + c + " is number");
}
else if (Char.IsSeparator(c))
{
Console.WriteLine("Char " + c + " is separator");
}
else if (Char.IsSymbol(c))
{
Console.WriteLine("Char " + c + " is symbol");
}
else if (Char.IsControl(c))
{
Console.WriteLine("Char " + c + " is control");
}
else if (Char.IsLetter(c))
{
Console.WriteLine("Char " + c + " is letter");
}
else if (Char.IsPunctuation(c))
{
Console.WriteLine("Char " + c + " is punctuation");
}
else if (Char.IsSurrogate(c))
{
Console.WriteLine("Char " + c + " is surrogate");
}
else if (Char.IsWhiteSpace(c))
{
Console.WriteLine("Char " + c + " is whitespace");
}

Console.ReadLine();
}
}
}
[/csharp]

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *