From bd6314de8bb113e2a317230f5e0fb6200c39a2e9 Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Mon, 15 Jul 2024 22:31:23 -0500 Subject: Move if_let syntax to convenience-features section (#4628) * Move if_let syntax to convenience-features section * Fix the syntax for setting up an anchor * update the comment on sample code * Add example for if_let syntax * Address the comments --- docs/user-guide/06-interfaces-generics.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'docs/user-guide/06-interfaces-generics.md') diff --git a/docs/user-guide/06-interfaces-generics.md b/docs/user-guide/06-interfaces-generics.md index 7935f3551..982b2ba8b 100644 --- a/docs/user-guide/06-interfaces-generics.md +++ b/docs/user-guide/06-interfaces-generics.md @@ -677,8 +677,10 @@ T compute(T a1, T a2) // compute(3, 1) == 2 ``` -`as` operator can also be used in the `if` predicate to test if an object can be casted to a specific type, once the cast test is successful, -the object can be used in the `if` block as the casted type without the need to retrieve the `Optional::value` property: +Since `as` operator returns a `Optional` type, it can also be used in the `if` predicate to test if an object can be +casted to a specific type, once the cast test is successful, the object can be used in the `if` block as the casted type +without the need to retrieve the `Optional::value` property, for example: + ```csharp interface IFoo { @@ -704,10 +706,10 @@ void test(IFoo foo) { // This syntax will be desugared to the following: // { - // Optional $OptVar = foo as MyImpl1; - // if ($OptVar.hasValue) + // Optional optVar = foo as MyImpl1; + // if (optVar.hasValue) // { - // MyImpl1 t = $OptVar.value; + // MyImpl1 t = optVar.value; // t.foo(); // } // else if ... @@ -734,6 +736,8 @@ void main() } ``` +See [if-let syntax](convenience-features.html#if_let-syntax) for more details. + Extensions to Interfaces ----------------------------- -- cgit v1.2.3