summaryrefslogtreecommitdiffstats
path: root/docs/user-guide
diff options
context:
space:
mode:
Diffstat (limited to 'docs/user-guide')
-rw-r--r--docs/user-guide/06-interfaces-generics.md22
1 files changed, 22 insertions, 0 deletions
diff --git a/docs/user-guide/06-interfaces-generics.md b/docs/user-guide/06-interfaces-generics.md
index bb19fd776..7c957f685 100644
--- a/docs/user-guide/06-interfaces-generics.md
+++ b/docs/user-guide/06-interfaces-generics.md
@@ -144,6 +144,28 @@ struct MyType<T, U>
}
```
+Optional conformances can be expressed compactly using the `where optional` syntax:
+```csharp
+// Together, these two overloads...
+int myGenericMethod<T>(T arg)
+{
+}
+
+int myGenericMethod<T>(T arg) where T: IFoo
+{
+ arg.myMethod(1.0);
+}
+
+// ... are equivalent to:
+int myGenericMethod<T>(T arg) where optional T: IFoo
+{
+ if (T is IFoo)
+ {
+ arg.myMethod(1.0); // OK in a block that checks for T: IFoo conformance.
+ }
+}
+```
+
Supported Constructs in Interface Definitions
-----------------------------------------------------