You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- 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
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.
63
63
64
64
## Static Methods
65
65
@@ -91,11 +91,22 @@ The following example illustrates a derived class that overrides a base class me
91
91
92
92
## Overloaded Methods
93
93
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
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:
99
110
100
111
```fsharp
101
112
open System.Runtime.InteropServices
@@ -104,7 +115,7 @@ type C() =
104
115
member _.M([<Optional; DefaultParameterValue(12)>] i) = i + 1
105
116
```
106
117
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.
0 commit comments