Skip to content

Revised comparison relational operator articles #9644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Operands of the [built-in value types](../keywords/value-types-table.md) are equ

[!code-csharp-interactive[value types equality](~/samples/snippets/csharp/language-reference/operators/EqualityAndNonEqualityExamples.cs#ValueTypesEquality)]

> [!NOTE]
> For relational operators `==`, `>`, `<`, `>=`, and `<=`, if any of the operands is not a number (<xref:System.Double.NaN?displayProperty=nameWithType> or <xref:System.Single.NaN?displayProperty=nameWithType>) the result of operation is `false`. That means that the `NaN` value is neither greater than, less than, nor equal to any other `double` (or `float`) value. For more information and examples, see the <xref:System.Double.NaN?displayProperty=nameWithType> or <xref:System.Single.NaN?displayProperty=nameWithType> reference article.

Two operands of the same [enum](../keywords/enum.md) type are equal if the corresponding values of the underlying integral type are equal.

By default, the `==` operator is not defined for a user-defined [struct](../keywords/struct.md) type. A user-defined type can [overload](#operator-overloadability) the `==` operator.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
title: "&gt;= Operator - C# Reference"
ms.custom: seodec18

ms.date: 07/20/2015
ms.date: 12/18/2018
f1_keywords:
- ">=_CSharpKeyword"
helpviewer_keywords:
Expand All @@ -11,16 +10,29 @@ helpviewer_keywords:
ms.assetid: 0db4dcaf-56a3-4884-a7ad-35f64978a58d
---
# &gt;= Operator (C# Reference)
All numeric and enumeration types define a "greater than or equal" relational operator, `>=` that returns `true` if the first operand is greater than or equal to the second, `false` otherwise.

## Remarks
User-defined types can overload the `>=` operator. For more information, see [operator](../../../csharp/language-reference/keywords/operator.md). If `>=` is overloaded, [<=](../../../csharp/language-reference/operators/less-than-equal-operator.md) must also be overloaded. Operations on integral types are generally allowed on enumeration.

## Example
[!code-csharp[csRefOperators#39](../../../csharp/language-reference/operators/codesnippet/CSharp/greater-than-equal-operator_1.cs)]

## See Also

- [C# Reference](../../../csharp/language-reference/index.md)
- [C# Programming Guide](../../../csharp/programming-guide/index.md)
- [C# Operators](../../../csharp/language-reference/operators/index.md)

The "greater than or equal" relational operator `>=` returns `true` if its first operand is greater than or equal to its second operand, `false` otherwise. All numeric and enumeration types support the `>=` operator. For operands of the same [enum](../keywords/enum.md) type, the corresponding values of the underlying integral type are compared.

> [!NOTE]
> For relational operators `==`, `>`, `<`, `>=`, and `<=`, if any of the operands is not a number (<xref:System.Double.NaN?displayProperty=nameWithType> or <xref:System.Single.NaN?displayProperty=nameWithType>) the result of operation is `false`. That means that the `NaN` value is neither greater than, less than, nor equal to any other `double` (or `float`) value. For more information and examples, see the <xref:System.Double.NaN?displayProperty=nameWithType> or <xref:System.Single.NaN?displayProperty=nameWithType> reference article.

The following example demonstrates the usage of the `>=` operator:

[!code-csharp-interactive[greater than or equal example](~/samples/snippets/csharp/language-reference/operators/GreaterAndLessOperatorsExamples.cs#GreaterOrEqual)]

## Operator overloadability

User-defined types can [overload](../keywords/operator.md) the `>=` operator. If a type overloads the "greater than or equal" operator `>=`, it must also overload the ["less than or equal" operator](less-than-equal-operator.md) `<=`.

## C# language specification

For more information, see the [Relational and type-testing operators](~/_csharplang/spec/expressions.md#relational-and-type-testing-operators) section of the [C# language specification](../language-specification/index.md).

## See also

- [C# Reference](../index.md)
- [C# Programming Guide](../../programming-guide/index.md)
- [C# Operators](index.md)
- [> Operator](greater-than-operator.md)
- [== Operator](equality-comparison-operator.md)
- <xref:System.IComparable%601?displayProperty=nameWithType>
42 changes: 26 additions & 16 deletions docs/csharp/language-reference/operators/greater-than-operator.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
title: "&gt; Operator - C# Reference"
ms.custom: seodec18

ms.date: 07/20/2015
ms.date: 12/18/2018
f1_keywords:
- ">_CSharpKeyword"
helpviewer_keywords:
Expand All @@ -11,17 +10,28 @@ helpviewer_keywords:
ms.assetid: 26d3cb69-9c0b-4cc5-858b-5be1abd6659d
---
# &gt; Operator (C# Reference)
All numeric and enumeration types define a "greater than" relational operator (`>`) that returns `true` if the first operand is greater than the second, `false` otherwise.

## Remarks
User-defined types can overload the `>` operator (see [operator](../../../csharp/language-reference/keywords/operator.md)). If `>` is overloaded, [<](../../../csharp/language-reference/operators/less-than-operator.md) must also be overloaded.

## Example
[!code-csharp[csRefOperators#29](../../../csharp/language-reference/operators/codesnippet/CSharp/greater-than-operator_1.cs)]

## See Also

- [C# Reference](../../../csharp/language-reference/index.md)
- [C# Programming Guide](../../../csharp/programming-guide/index.md)
- [C# Operators](../../../csharp/language-reference/operators/index.md)
- [explicit](../../../csharp/language-reference/keywords/explicit.md)

The "greater than" relational operator `>` returns `true` if its first operand is greater than its second operand, `false` otherwise. All numeric and enumeration types support the `>` operator. For operands of the same [enum](../keywords/enum.md) type, the corresponding values of the underlying integral type are compared.

> [!NOTE]
> For relational operators `==`, `>`, `<`, `>=`, and `<=`, if any of the operands is not a number (<xref:System.Double.NaN?displayProperty=nameWithType> or <xref:System.Single.NaN?displayProperty=nameWithType>) the result of operation is `false`. That means that the `NaN` value is neither greater than, less than, nor equal to any other `double` (or `float`) value. For more information and examples, see the <xref:System.Double.NaN?displayProperty=nameWithType> or <xref:System.Single.NaN?displayProperty=nameWithType> reference article.

The following example demonstrates the usage of the `>` operator:

[!code-csharp-interactive[greater than example](~/samples/snippets/csharp/language-reference/operators/GreaterAndLessOperatorsExamples.cs#Greater)]

## Operator overloadability

User-defined types can [overload](../keywords/operator.md) the `>` operator. If a type overloads the "greater than" operator `>`, it must also overload the ["less than" operator](less-than-operator.md) `<`.

## C# language specification

For more information, see the [Relational and type-testing operators](~/_csharplang/spec/expressions.md#relational-and-type-testing-operators) section of the [C# language specification](../language-specification/index.md).

## See also

- [C# Reference](../index.md)
- [C# Programming Guide](../../programming-guide/index.md)
- [C# Operators](index.md)
- [>= Operator](greater-than-equal-operator.md)
- <xref:System.IComparable%601?displayProperty=nameWithType>
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
title: "&lt;= Operator - C# Reference"
ms.custom: seodec18

ms.date: 07/20/2015
ms.date: 12/18/2018
f1_keywords:
- "<=_CSharpKeyword"
helpviewer_keywords:
Expand All @@ -11,17 +10,29 @@ helpviewer_keywords:
ms.assetid: bb0caec9-d253-4105-b8bc-5252233251e4
---
# &lt;= Operator (C# Reference)
All numeric and enumeration types define a "less than or equal" relational operator (`<=`) that returns `true` if the first operand is less than or equal to the second, `false` otherwise.

## Remarks
User-defined types can overload the `<=` operator. For more information, see [operator](../../../csharp/language-reference/keywords/operator.md). If `<=` is overloaded, [>=](../../../csharp/language-reference/operators/greater-than-equal-operator.md) must also be overloaded. Operations on integral types are generally allowed on enumeration.

## Example
[!code-csharp[csRefOperators#32](../../../csharp/language-reference/operators/codesnippet/CSharp/less-than-equal-operator_1.cs)]

## See Also

- [C# Reference](../../../csharp/language-reference/index.md)
- [C# Programming Guide](../../../csharp/programming-guide/index.md)
- [C# Operators](../../../csharp/language-reference/operators/index.md)
- [explicit](../../../csharp/language-reference/keywords/explicit.md)

The "less than or equal" relational operator `<=` returns `true` if its first operand is less than or equal to its second operand, `false` otherwise. All numeric and enumeration types support the `<=` operator. For operands of the same [enum](../keywords/enum.md) type, the corresponding values of the underlying integral type are compared.

> [!NOTE]
> For relational operators `==`, `>`, `<`, `>=`, and `<=`, if any of the operands is not a number (<xref:System.Double.NaN?displayProperty=nameWithType> or <xref:System.Single.NaN?displayProperty=nameWithType>) the result of operation is `false`. That means that the `NaN` value is neither greater than, less than, nor equal to any other `double` (or `float`) value. For more information and examples, see the <xref:System.Double.NaN?displayProperty=nameWithType> or <xref:System.Single.NaN?displayProperty=nameWithType> reference article.

The following example demonstrates the usage of the `<=` operator:

[!code-csharp-interactive[less than or equal example](~/samples/snippets/csharp/language-reference/operators/GreaterAndLessOperatorsExamples.cs#LessOrEqual)]

## Operator overloadability

User-defined types can [overload](../keywords/operator.md) the `<=` operator. If a type overloads the "less than or equal" operator `<=`, it must also overload the ["greater than or equal" operator](greater-than-equal-operator.md) `>=`.

## C# language specification

For more information, see the [Relational and type-testing operators](~/_csharplang/spec/expressions.md#relational-and-type-testing-operators) section of the [C# language specification](../language-specification/index.md).

## See also

- [C# Reference](../index.md)
- [C# Programming Guide](../../programming-guide/index.md)
- [C# Operators](index.md)
- [< Operator](less-than-operator.md)
- [== Operator](equality-comparison-operator.md)
- <xref:System.IComparable%601?displayProperty=nameWithType>
41 changes: 26 additions & 15 deletions docs/csharp/language-reference/operators/less-than-operator.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
title: "&lt; Operator - C# Reference"
ms.custom: seodec18

ms.date: 07/20/2015
ms.date: 12/18/2018
f1_keywords:
- "<_CSharpKeyword"
helpviewer_keywords:
Expand All @@ -11,16 +10,28 @@ helpviewer_keywords:
ms.assetid: 38cb91e6-79a6-48ec-9c1e-7b71fd8d2b41
---
# &lt; Operator (C# Reference)
All numeric and enumeration types define a "less than" relational operator (`<`) that returns `true` if the first operand is less than the second, `false` otherwise.

## Remarks
User-defined types can overload the `<` operator (see [operator](../../../csharp/language-reference/keywords/operator.md)). If `<` is overloaded, [>](../../../csharp/language-reference/operators/greater-than-operator.md) must also be overloaded.

## Example
[!code-csharp[csRefOperators#24](../../../csharp/language-reference/operators/codesnippet/CSharp/less-than-operator_1.cs)]

## See Also

- [C# Reference](../../../csharp/language-reference/index.md)
- [C# Programming Guide](../../../csharp/programming-guide/index.md)
- [C# Operators](../../../csharp/language-reference/operators/index.md)

The "less than" relational operator `<` returns `true` if its first operand is less than its second operand, `false` otherwise. All numeric and enumeration types support the `<` operator. For operands of the same [enum](../keywords/enum.md) type, the corresponding values of the underlying integral type are compared.

> [!NOTE]
> For relational operators `==`, `>`, `<`, `>=`, and `<=`, if any of the operands is not a number (<xref:System.Double.NaN?displayProperty=nameWithType> or <xref:System.Single.NaN?displayProperty=nameWithType>) the result of operation is `false`. That means that the `NaN` value is neither greater than, less than, nor equal to any other `double` (or `float`) value. For more information and examples, see the <xref:System.Double.NaN?displayProperty=nameWithType> or <xref:System.Single.NaN?displayProperty=nameWithType> reference article.

The following example demonstrates the usage of the `<` operator:

[!code-csharp-interactive[less than example](~/samples/snippets/csharp/language-reference/operators/GreaterAndLessOperatorsExamples.cs#Less)]

## Operator overloadability

User-defined types can [overload](../keywords/operator.md) the `<` operator. If a type overloads the "less than" operator `<`, it must also overload the ["greater than" operator](greater-than-operator.md) `>`.

## C# language specification

For more information, see the [Relational and type-testing operators](~/_csharplang/spec/expressions.md#relational-and-type-testing-operators) section of the [C# language specification](../language-specification/index.md).

## See also

- [C# Reference](../index.md)
- [C# Programming Guide](../../programming-guide/index.md)
- [C# Operators](index.md)
- [<= Operator](less-than-equal-operator.md)
- <xref:System.IComparable%601?displayProperty=nameWithType>