Compare char value

In this chapter you will learn:

  1. Compares to another Char

Compares to another Char

We can use the CompareTo(char value) method to compare two char values: The CompareTo(char value) returns the following values:

Return ValueDescription
Less than zeroThis instance precedes value.
ZeroThis instance has the same position in the sort order as value.
Greater than zeroThis instance follows value.
using System;//from j av a  2  s  .c o m

class Sample 
{
    public static void Main() 
    {
       char ch='A';
       
       int result = ch.CompareTo('B');
    
       Console.WriteLine(result);
    }
}

The output:

Next chapter...

What you will learn in the next chapter:

  1. Find out the char min/max value
Home » C# Tutorial » bool, char
bool
bool and if statement
bool value to string
Parse string to bool value
char type
char escape sequence
char case
Compare char value
char min/max value
Is char a digit
Is char a letter
Is char a symbol
Is char a Separator
Is char white space
Convert to char
UTF-16 Character