diff options
| -rw-r--r-- | docs/user-guide/03-convenience-features.md | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/docs/user-guide/03-convenience-features.md b/docs/user-guide/03-convenience-features.md index e67166644..09e15c205 100644 --- a/docs/user-guide/03-convenience-features.md +++ b/docs/user-guide/03-convenience-features.md @@ -336,7 +336,7 @@ Please note that the support for inheritance is currently very limited. Common f Extensions -------------------- -Slang allows defining additional members for a type outside its initial definition. For example, suppose we already have a type defined: +Slang allows defining additional methods for a type outside its initial definition. For example, suppose we already have a type defined: ```csharp struct MyType @@ -346,11 +346,10 @@ struct MyType } ``` -You can extend `MyType` with new members: +You can extend `MyType` with new method members: ```csharp extension MyType { - float newField; float getNewField() { return newField; } } ``` @@ -361,13 +360,15 @@ All locations that sees the definition of the `extension` can access the new mem void test() { MyType t; - t.newField = 1.0; float val = t.getNewField(); } ``` This feature is similar to extensions in Swift and partial classes in C#. +> #### Note: +> You can only extend a type with additional methods. Extending with additiional data fields is not allowed. + Multi-level break ------------------- |
