Skip to content

Commit 0ccfa37

Browse files
authored
Update properties.md (#47613)
- Fix code example indentation - Add single backticks to highlight class properties
1 parent 7d1f176 commit 0ccfa37

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ Private values that hold the data for properties are called *backing stores*. To
6666

6767
```fsharp
6868
type MyClass(property1 : int) =
69-
member val Property1 = property1
70-
member val Property2 = "" with get, set
69+
member val Property1 = property1
70+
member val Property2 = "" with get, set
7171
```
7272

7373
Automatically implemented properties are part of the initialization of a type, so they must be included before any other member definitions, just like `let` bindings and `do` bindings in a type definition. Note that the expression that initializes an automatically implemented property is only evaluated upon initialization, and not every time the property is accessed. This behavior is in contrast to the behavior of an explicitly implemented property. What this effectively means is that the code to initialize these properties is added to the constructor of a class. Consider the following code that shows this difference:
@@ -93,7 +93,7 @@ class1.ExplicitProperty = 978922705
9393
class1.ExplicitProperty = 1131210765
9494
```
9595

96-
The output of the preceding code shows that the value of AutoProperty is unchanged when called repeatedly, whereas the ExplicitProperty changes each time it is called. This demonstrates that the expression for an automatically implemented property is not evaluated each time, as is the getter method for the explicit property.
96+
The output of the preceding code shows that the value of `AutoProperty` is unchanged when called repeatedly, whereas the `ExplicitProperty` changes each time it is called. This demonstrates that the expression for an automatically implemented property is not evaluated each time, as is the getter method for the explicit property.
9797

9898
>[!WARNING]
9999
>There are some libraries, such as the Entity Framework (`System.Data.Entity`) that perform custom operations in base class constructors that don't work well with the initialization of automatically implemented properties. In those cases, try using explicit properties.

0 commit comments

Comments
 (0)