Skip to content

Commit b66f2bb

Browse files
authored
Example metadata: expressions.md, revisited (#718)
* have example generate output * minor tweak to example * use new template code-in-partial-class * Create Library.cs * Create Project.csproj * Create Caller.cs
1 parent b750cad commit b66f2bb

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

standard/expressions.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4753,7 +4753,6 @@ If a for-loop declares an iteration variable, that variable itself is considered
47534753
> *Example*: Thus, if the example is changed to capture the iteration variable itself:
47544754
>
47554755
> <!-- Example: {template:"standalone-console", name:"InstantiationOfLocalVariables5", inferOutput: true} -->
4756-
> <!-- Maintenance Note: A version of this delegate type exists in additional-files as "DvoidNoArgs.cs". As such, certain changes to this type definition might need to be reflected in that file, in which case, *all* examples using that file should be tested. -->
47574756
> ```csharp
47584757
> delegate void D();
47594758
>
@@ -4793,7 +4792,7 @@ It is possible for anonymous function delegates to share some captured variables
47934792

47944793
> *Example*: For example, if `F` is changed to
47954794
>
4796-
> <!-- Example: {template:"standalone-console", name:"InstantiationOfLocalVariables6", IgnoredWarnings:["CS8321"], additionalFiles:["DvoidNoArgs.cs"]} -->
4795+
> <!-- Example: {template:"code-in-partial-class", name:"InstantiationOfLocalVariables6", IgnoredWarnings:["CS8321"], additionalFiles:["Caller.cs"], inferOutput: true} -->
47974796
> ```csharp
47984797
> static D[] F()
47994798
> {
@@ -4808,7 +4807,15 @@ It is possible for anonymous function delegates to share some captured variables
48084807
> }
48094808
> ```
48104809
>
4811-
> the three delegates capture the same instance of `x` but separate instances of `y`. *end example*
4810+
> the three delegates capture the same instance of `x` but separate instances of `y`, and the output is:
4811+
>
4812+
> ```console
4813+
> 1 1
4814+
> 2 1
4815+
> 3 1
4816+
> ```
4817+
>
4818+
> *end example*
48124819

48134820
Separate anonymous functions can capture the same instance of an outer variable.
48144821

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
delegate void D();
2+
3+
partial class Class1
4+
{
5+
static void Main()
6+
{
7+
foreach (D d in F())
8+
{
9+
d();
10+
}
11+
}
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections;
4+
using System.Diagnostics;
5+
using System.IO;
6+
using System.Linq.Expressions;
7+
using System.Reflection;
8+
using System.Runtime.CompilerServices;
9+
using System.Runtime.InteropServices;
10+
using System.Security.Permissions;
11+
using System.Text;
12+
using System.Threading;
13+
14+
partial class Class1
15+
{
16+
$example-code
17+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<AssemblyName>$example-name</AssemblyName>
8+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
9+
</PropertyGroup>
10+
11+
</Project>

0 commit comments

Comments
 (0)