diff options
| author | Yong He <yonghe@outlook.com> | 2023-05-04 12:30:13 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-04 12:30:13 -0700 |
| commit | ee62b062e6b606c480c5f7358710b06c933b0efb (patch) | |
| tree | 6383bbb8577feb3571f539eb1a1e07dbcd119d07 /docs/user-guide | |
| parent | c9ef8d58a135061262fd321a82061d27dc733cf5 (diff) | |
Update 03-convenience-features.md
Diffstat (limited to 'docs/user-guide')
| -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 ------------------- |
