Skip to content

Commit

Permalink
Revised docs related to operator overloading (dotnet#7283)
Browse files Browse the repository at this point in the history
* Removed outdated article and updated operator keyword article

* Addressed feedback

* Addressed feedback

* Updated See also of the operator article
  • Loading branch information
pkulikov authored and Ron Petrusha committed Aug 27, 2018
1 parent 965f854 commit 25f4b77
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 128 deletions.
4 changes: 4 additions & 0 deletions .openpublishing.redirection.json
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,10 @@
{
"source_path":"docs/framework/wcf/feature-details/migrate-asp-net-web-service-client-to-wcf.md",
"redirect_url":"/dotnet/framework/wcf/feature-details/adopting-wcf"
},
{
"source_path":"docs/csharp/programming-guide/statements-expressions-operators/how-to-use-operator-overloading-to-create-a-complex-number-class.md",
"redirect_url":"/dotnet/csharp/language-reference/keywords/operator"
}
]
}
2 changes: 1 addition & 1 deletion docs/csharp/how-to/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ There are several tips and tricks that are common C# developer practices.
- [Learn the differences between passing a struct and a class to a method](../programming-guide/classes-and-structs/how-to-know-the-difference-passing-a-struct-and-passing-a-class-to-a-method.md).
- [How to use lambda expressions](../programming-guide/statements-expressions-operators/how-to-use-lambda-expressions-outside-linq.md).
- [Resolve type name conflicts by using the global namespace alias](../programming-guide/namespaces/how-to-use-the-global-namespace-alias.md).
- [Use operator overloading](../programming-guide/statements-expressions-operators/how-to-use-operator-overloading-to-create-a-complex-number-class.md).
- [Use operator overloading](../language-reference/keywords/operator.md).
- [Implement and call a custom extension method](../programming-guide/classes-and-structs/how-to-implement-and-call-a-custom-extension-method.md).
- Even C# programmers may want to [use the `My` namespace from VB](../programming-guide/namespaces/how-to-use-the-my-namespace.md).
- [Create a new method for an `enum` type using extension methods](../programming-guide/classes-and-structs/how-to-create-a-new-method-for-an-enumeration.md).
Expand Down
16 changes: 14 additions & 2 deletions docs/csharp/language-reference/keywords/operator.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: "operator keyword (C# Reference)"
ms.date: 07/20/2015
description: "Learn how to overload a built-in C# operator"
ms.date: 08/27/2018
f1_keywords:
- "operator_CSharpKeyword"
- "operator"
Expand All @@ -12,9 +13,19 @@ ms.assetid: 59218cce-e90e-42f6-a6bb-30300981b86a

Use the `operator` keyword to overload a built-in operator or to provide a user-defined conversion in a class or struct declaration.

To overload an operator on a custom class or struct, you create an operator declaration in the corresponding type. The operator declaration that overloads a built-in C# operator must satisfy the following rules:

- It includes both a `public` and a `static` modifier.
- It includes `operator X` where `X` is the name or symbol of the operator being overloaded.
- Unary operators have one parameter, and binary operators have two parameters. In each case, at least one parameter must be the same type as the class or struct that declares the operator.

For information about how to define conversion operators, see the [explicit](explicit.md) and [implicit](implicit.md) keyword articles.

For an overview of the C# operators that can be overloaded, see the [Overloadable operators](../../programming-guide/statements-expressions-operators/overloadable-operators.md) article.

## Example

The following is a very simplified class for fractional numbers. It overloads the `+` and `*` operators to perform fractional addition and multiplication, and also provides a conversion operator that converts a `Fraction` type to a `double` type.
The following example defines a `Fraction` type that represents fractional numbers. It overloads the `+` and `*` operators to perform fractional addition and multiplication, and also provides a conversion operator that converts a `Fraction` type to a `double` type.

[!code-csharp[csrefKeywordsConversion#6](~/samples/snippets/csharp/VS_Snippets_VBCSharp/csrefKeywordsConversion/CS/csrefKeywordsConversion.cs#6)]

Expand All @@ -29,4 +40,5 @@ The following is a very simplified class for fractional numbers. It overloads th
- [C# Keywords](index.md)
- [implicit](implicit.md)
- [explicit](explicit.md)
- [Overloadable operators](../../programming-guide/statements-expressions-operators/overloadable-operators.md)
- [How to: Implement User-Defined Conversions Between Structs](../../programming-guide/statements-expressions-operators/how-to-implement-user-defined-conversions-between-structs.md)

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,25 @@ The C# code that comprises an application consists of statements made up of keyw

For more information, see:

- [Statements](../../../csharp/programming-guide/statements-expressions-operators/statements.md)
- [Statements](statements.md)

- [Expressions](../../../csharp/programming-guide/statements-expressions-operators/expressions.md)
- [Expressions](expressions.md)

- [Expression-bodied members](expression-bodied-members.md)

- [Operators](../../../csharp/programming-guide/statements-expressions-operators/operators.md)
- [Operators](operators.md)

- [Anonymous Functions](../../../csharp/programming-guide/statements-expressions-operators/anonymous-functions.md)
- [Anonymous Functions](anonymous-functions.md)

- [Overloadable Operators](../../../csharp/programming-guide/statements-expressions-operators/overloadable-operators.md)
- [Overloadable Operators](overloadable-operators.md)

- [Conversion Operators](../../../csharp/programming-guide/statements-expressions-operators/conversion-operators.md)
- [Conversion Operators](conversion-operators.md)

- [Using Conversion Operators](../../../csharp/programming-guide/statements-expressions-operators/using-conversion-operators.md)
- [Using Conversion Operators](using-conversion-operators.md)

- [How to: Implement User-Defined Conversions Between Structs](../../../csharp/programming-guide/statements-expressions-operators/how-to-implement-user-defined-conversions-between-structs.md)
- [How to: Implement User-Defined Conversions Between Structs](how-to-implement-user-defined-conversions-between-structs.md)

- [How to: Use Operator Overloading to Create a Complex Number Class](../../../csharp/programming-guide/statements-expressions-operators/how-to-use-operator-overloading-to-create-a-complex-number-class.md)

- [Equality Comparisons](../../../csharp/programming-guide/statements-expressions-operators/equality-comparisons.md)
- [Equality Comparisons](equality-comparisons.md)

## C# Language Specification
[!INCLUDE[CSharplangspec](~/includes/csharplangspec-md.md)]
Expand Down
Loading

0 comments on commit 25f4b77

Please sign in to comment.