Ejercicio
Función IsAlphabetic
Objetivo
Cree una función que indique si un carácter es alfabético (de la A a la Z) o no. Debe usarse así:
if (IsAlphabetic ("a"))
System.Console.WriteLine ("Es un carácter alfabético");
(Nota: no te preocupes por los acentos y ñ)
Código de Ejemplo
// Import the System namespace to use basic classes like Console
using System;
class Program
{
// Main method to drive the program
public static void Main()
{
// Test the IsAlphabetic function
if (IsAlphabetic("a"))
{
Console.WriteLine("It is an alphabetic character");
}
else
{
Console.WriteLine("It is not an alphabetic character");
}
if (IsAlphabetic("1"))
{
Console.WriteLine("It is an alphabetic character");
}
else
{
Console.WriteLine("It is not an alphabetic character");
}
}
// Function to check if a character is alphabetic
public static bool IsAlphabetic(string str)
{
// Check if the string contains exactly one character and it is a letter
return str.Length == 1 && char.IsLetter(str[0]);
}
}