Skip to content

Commit 167b223

Browse files
authored
Update methods.md (#47616)
- Improve consistency by using single backticks to highlight the `let` binding at the text - Add example to method overload - Improve text - Remove unnecessary white spaces
1 parent 3dbc6c4 commit 167b223

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

docs/fsharp/language-reference/members/methods.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ The following example illustrates the definition and use of a non-abstract insta
5959

6060
[!code-fsharp[Main](~/samples/snippets/fsharp/lang-ref-1/snippet3401.fs)]
6161

62-
Within instance methods, do not use the self identifier to access fields defined by using let bindings. Use the self identifier when accessing other members and properties.
62+
Within instance methods, do not use the self identifier to access fields defined by using `let` bindings. Use the self identifier when accessing other members and properties.
6363

6464
## Static Methods
6565

@@ -91,11 +91,22 @@ The following example illustrates a derived class that overrides a base class me
9191

9292
## Overloaded Methods
9393

94-
Overloaded methods are methods that have identical names in a given type but that have different arguments. In F#, optional arguments are usually used instead of overloaded methods. However, overloaded methods are permitted in the language, provided that the arguments are in tuple form, not curried form.
94+
Overloaded methods are methods that have identical names in a given type but that have different arguments. In F#, optional arguments are usually used instead of overloaded methods. However, overloaded methods are permitted in the language, provided that the arguments are in tuple form, not curried form. The following example demonstrates it:
95+
96+
```fsharp
97+
type MyType(dataIn: int) =
98+
let data = dataIn
99+
member this.DoSomething(a: int) = a + data
100+
member this.DoSomething(a: string) = sprintf "Hello world, %s!" a
101+
102+
let m = MyType(10)
103+
printfn "With int: %d" (m.DoSomething(2)) // With int: 12
104+
printfn "With string: %s" (m.DoSomething("Bill")) // With string: Hello world, Bill!
105+
```
95106

96107
## Optional Arguments
97108

98-
Starting with F# 4.1, you can also have optional arguments with a default parameter value in methods. This is to help facilitate interoperation with C# code. The following example demonstrates the syntax:
109+
Starting with F# 4.1, you can also have optional arguments with a default parameter value in methods. This improves interoperability with C# code. The following example demonstrates the syntax:
99110

100111
```fsharp
101112
open System.Runtime.InteropServices
@@ -104,7 +115,7 @@ type C() =
104115
member _.M([<Optional; DefaultParameterValue(12)>] i) = i + 1
105116
```
106117

107-
Note that the value passed in for `DefaultParameterValue` must match the input type. In the above sample, it is an `int`. Attempting to pass a non-integer value into `DefaultParameterValue` would result in a compile error.
118+
Note that the value passed in for `DefaultParameterValue` must match the input type. In the above example, it is an `int`. Attempting to pass a non-integer value into `DefaultParameterValue` would result in a compile error.
108119

109120
## Example: Properties and Methods
110121

0 commit comments

Comments
 (0)