Function Isalphabetic - C# Programming Exercise

In this exercise of C#, you will learn how to create a function that tells if a character is alphabetic (from A to Z) or not. This function should be used like this: if (IsAlphabetic("a")) System.Console.WriteLine("It is an alphabetic character");. In this case, if the character is a letter between A and Z, the function will return true and print the message "It is an alphabetic character". This exercise is great for practicing character manipulation in C#, working with conditionals, and using the System.Console.WriteLine function. Note that in this exercise, you do not need to worry about accents or the ñ letter, which simplifies the process by limiting the alphabetic characters to only unmodified letters. With this exercise, you'll improve your ability to work with text strings and validate characters within those strings.

This type of function is useful for situations where you need to check the nature of a character before processing it or performing a specific action in a program.

 Category

Functions

 Exercise

Function Isalphabetic

 Objective

Write a C# function that tells if a character is alphabetic (A through Z) or not. It should be used like this:

if (IsAlphabetic ("a"))
System.Console.WriteLine ("It is an alphabetic character");

(Note: do not worry about accents and ñ)

 Write Your C# Exercise

// 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]);
    }
}

 Share this C# exercise

 More C# Programming Exercises of Functions

Explore our set of C# programming exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C#. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C#.

  •  Function IsNumber

    In this exercise of C#, you will learn how to create a function that tells if a text string represents an integer number. This function should be used l...

  •  Function calculator, params of Main

    In this exercise of C#, you will learn how to create a program that performs mathematical operations such as addition, subtraction, multiplication, or division...

  •  Function calculator, params and return value of Main

    In this exercise of C#, you will create a program that calculates mathematical operations like addition, subtraction, multiplication, or division, by analyzing...

  •  Function MinMaxArray

    In this exercise of C#, you will create a function named MinMaxArray that receives an array of numbers and returns the minimum and maximum values using ...

  •  Function Reverse, recursive

    In this exercise of C#, you need to create a program that uses recursion to reverse a string of characters. The program should receive a string as input...

  •  Function WriteRectangle

    In this exercise of C#, you need to create two functions: one called WriteRectangle to display a filled rectangle on the screen using asterisks, and another ca...