A character can be checked whether it is within a specific range. This can be easily done because each char represent the integer value. You can use the built-in comparison support for the char data type. The code below shows the example of this.

public static bool IsInRange(char c, char startChar, char endChar)
{
    if (c >= startChar && c <= endChar)
    {
        return true;
    }
    else
    {
        return false;
    }
}

The IsInRange method accepts three parameters. The first is the character to check, to test if it falls between the last two parameters on this method. The last two parameters are the starting and ending characters, respectively, of a range of characters. If the character c to test is between startChar and endChar, the method returns true, otherwise false. The code below show you using the above method.

bool blnInRange = IsInRange(''o'', ''m'', ''y''); // return true
bool blnInRange = IsInRange(''o'', ''s'', ''y''); // return false

Popularity: 1% [?]