Compartir a través de


Pointer Comparison (C# Programming Guide)

You can apply the following operators to compare pointers of any type:

==   !=   <   >   <=   >=

The comparison operators compare the addresses of the two operands as if they are unsigned integers.

Example

// compile with: /unsafe
class CompareOperators
{
    unsafe static void Main() 
    {
        int x = 234;
        int y = 236;
        int* p1 = &x;
        int* p2 = &y;

        System.Console.WriteLine(p1 < p2);
        System.Console.WriteLine(p2 < p1);
    }
}

Sample Output

True

False

See Also

Reference

Pointer Expressions (C# Programming Guide)

C# Operators

Manipulating Pointers (C# Programming Guide)

Pointer types (C# Programming Guide)

unsafe (C# Reference)

fixed Statement (C# Reference)

stackalloc (C# Reference)

Concepts

C# Programming Guide

Other Resources

Types (C# Reference)