From 661cd34f6c896a1d118e4e64107b380555030ad8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:01:04 +0000 Subject: [PATCH 01/24] Bump coverlet.collector Bumps [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 3.1.2 to 3.2.0. - [Release notes](https://github.com/coverlet-coverage/coverlet/releases) - [Commits](https://github.com/coverlet-coverage/coverlet/commits/v3.2.0) --- updated-dependencies: - dependency-name: coverlet.collector dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../StringLibraryTest/StringLibraryTest.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/csharp/getting_started/ClassLibraryProjects/StringLibraryTest/StringLibraryTest.csproj b/samples/snippets/csharp/getting_started/ClassLibraryProjects/StringLibraryTest/StringLibraryTest.csproj index 6069bb0cdf29d..528206225e584 100644 --- a/samples/snippets/csharp/getting_started/ClassLibraryProjects/StringLibraryTest/StringLibraryTest.csproj +++ b/samples/snippets/csharp/getting_started/ClassLibraryProjects/StringLibraryTest/StringLibraryTest.csproj @@ -10,7 +10,7 @@ - + From f3478ff716149d0483d10636fc6ff57514c57d89 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:01:06 +0000 Subject: [PATCH 02/24] Bump NUnit3TestAdapter Bumps [NUnit3TestAdapter](https://github.com/nunit/nunit3-vs-adapter) from 4.2.1 to 4.3.0. - [Release notes](https://github.com/nunit/nunit3-vs-adapter/releases) - [Commits](https://github.com/nunit/nunit3-vs-adapter/compare/V4.2.1...V4.3.0) --- updated-dependencies: - dependency-name: NUnit3TestAdapter dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../csharp/PrimeService.Tests/PrimeService.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/core/testing/unit-testing-using-nunit/csharp/PrimeService.Tests/PrimeService.Tests.csproj b/samples/snippets/core/testing/unit-testing-using-nunit/csharp/PrimeService.Tests/PrimeService.Tests.csproj index 2fdf7824479bd..df6eef4d7e028 100644 --- a/samples/snippets/core/testing/unit-testing-using-nunit/csharp/PrimeService.Tests/PrimeService.Tests.csproj +++ b/samples/snippets/core/testing/unit-testing-using-nunit/csharp/PrimeService.Tests/PrimeService.Tests.csproj @@ -9,7 +9,7 @@ - + From 3b06d89e919f320349e35b9f21e1d0cac58b62df Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:01:07 +0000 Subject: [PATCH 03/24] Bump NUnit3TestAdapter Bumps [NUnit3TestAdapter](https://github.com/nunit/nunit3-vs-adapter) from 4.2.1 to 4.3.0. - [Release notes](https://github.com/nunit/nunit3-vs-adapter/releases) - [Commits](https://github.com/nunit/nunit3-vs-adapter/compare/V4.2.1...V4.3.0) --- updated-dependencies: - dependency-name: NUnit3TestAdapter dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../vb/PrimeService.Tests/PrimeService.Tests.vbproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/core/testing/unit-testing-vb-nunit/vb/PrimeService.Tests/PrimeService.Tests.vbproj b/samples/snippets/core/testing/unit-testing-vb-nunit/vb/PrimeService.Tests/PrimeService.Tests.vbproj index 633117a9a127e..d68090bfd89b7 100644 --- a/samples/snippets/core/testing/unit-testing-vb-nunit/vb/PrimeService.Tests/PrimeService.Tests.vbproj +++ b/samples/snippets/core/testing/unit-testing-vb-nunit/vb/PrimeService.Tests/PrimeService.Tests.vbproj @@ -9,7 +9,7 @@ - + From 46d61416f3328a022ecac172fde9698241a92a90 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:01:17 +0000 Subject: [PATCH 04/24] Bump coverlet.collector Bumps [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 3.1.2 to 3.2.0. - [Release notes](https://github.com/coverlet-coverage/coverlet/releases) - [Commits](https://github.com/coverlet-coverage/coverlet/commits/v3.2.0) --- updated-dependencies: - dependency-name: coverlet.collector dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../csharp/StringLibraryTest/StringLibraryTest.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/tutorials/snippets/library-with-visual-studio/csharp/StringLibraryTest/StringLibraryTest.csproj b/docs/core/tutorials/snippets/library-with-visual-studio/csharp/StringLibraryTest/StringLibraryTest.csproj index f36cff95a2995..a6af0f8e818d3 100644 --- a/docs/core/tutorials/snippets/library-with-visual-studio/csharp/StringLibraryTest/StringLibraryTest.csproj +++ b/docs/core/tutorials/snippets/library-with-visual-studio/csharp/StringLibraryTest/StringLibraryTest.csproj @@ -10,7 +10,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 0f0ea71892e706cfe350ac4663c7c100f66af526 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:34:53 +0000 Subject: [PATCH 05/24] Bump actions/setup-dotnet from 3.0.2 to 3.0.3 Bumps [actions/setup-dotnet](https://github.com/actions/setup-dotnet) from 3.0.2 to 3.0.3. - [Release notes](https://github.com/actions/setup-dotnet/releases) - [Commits](https://github.com/actions/setup-dotnet/compare/4d4a70f4a5b2a5a5329f13be4ac933f2c9206ac0...607fce577a46308457984d59e4954e075820f10a) --- updated-dependencies: - dependency-name: actions/setup-dotnet dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/whats-new.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/whats-new.yml b/.github/workflows/whats-new.yml index 5af3616352a23..b0428e0ab28d2 100644 --- a/.github/workflows/whats-new.yml +++ b/.github/workflows/whats-new.yml @@ -32,7 +32,7 @@ jobs: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 - name: Setup .NET - uses: actions/setup-dotnet@4d4a70f4a5b2a5a5329f13be4ac933f2c9206ac0 + uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a with: dotnet-version: ${{ env.DOTNET_VERSION }} From 1e8c9283153b4a115b9f82525f1a936798dcefd0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:36:32 +0000 Subject: [PATCH 06/24] Bump coverlet.collector Bumps [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 3.1.2 to 3.2.0. - [Release notes](https://github.com/coverlet-coverage/coverlet/releases) - [Commits](https://github.com/coverlet-coverage/coverlet/commits/v3.2.0) --- updated-dependencies: - dependency-name: coverlet.collector dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../csharp/PrimeService.Tests/PrimeService.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/testing/snippets/unit-testing-using-mstest/csharp/PrimeService.Tests/PrimeService.Tests.csproj b/docs/core/testing/snippets/unit-testing-using-mstest/csharp/PrimeService.Tests/PrimeService.Tests.csproj index 414cd9b34ede7..075b9c51c423d 100644 --- a/docs/core/testing/snippets/unit-testing-using-mstest/csharp/PrimeService.Tests/PrimeService.Tests.csproj +++ b/docs/core/testing/snippets/unit-testing-using-mstest/csharp/PrimeService.Tests/PrimeService.Tests.csproj @@ -10,7 +10,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 75cde7721fbc803c19382b4e1a8d972587a6d41b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:36:32 +0000 Subject: [PATCH 07/24] Bump NUnit3TestAdapter Bumps [NUnit3TestAdapter](https://github.com/nunit/nunit3-vs-adapter) from 4.2.1 to 4.3.0. - [Release notes](https://github.com/nunit/nunit3-vs-adapter/releases) - [Commits](https://github.com/nunit/nunit3-vs-adapter/compare/V4.2.1...V4.3.0) --- updated-dependencies: - dependency-name: NUnit3TestAdapter dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../csharp/NUnit.TestProject/NUnit.Project.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/testing/snippets/order-unit-tests/csharp/NUnit.TestProject/NUnit.Project.csproj b/docs/core/testing/snippets/order-unit-tests/csharp/NUnit.TestProject/NUnit.Project.csproj index ad4d6e85d001c..097b74635bfa9 100644 --- a/docs/core/testing/snippets/order-unit-tests/csharp/NUnit.TestProject/NUnit.Project.csproj +++ b/docs/core/testing/snippets/order-unit-tests/csharp/NUnit.TestProject/NUnit.Project.csproj @@ -9,7 +9,7 @@ - + From d29843053011053e69615c919807eda6b0f2670c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:36:33 +0000 Subject: [PATCH 08/24] Bump Microsoft.Windows.Compatibility Bumps [Microsoft.Windows.Compatibility](https://github.com/dotnet/runtime) from 6.0.0 to 6.0.1. - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](https://github.com/dotnet/runtime/compare/v6.0.0...v6.0.1) --- updated-dependencies: - dependency-name: Microsoft.Windows.Compatibility dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../VS_Snippets_CLR/CryptoWalkThru/cs/cryptowalkthru.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/csharp/VS_Snippets_CLR/CryptoWalkThru/cs/cryptowalkthru.csproj b/samples/snippets/csharp/VS_Snippets_CLR/CryptoWalkThru/cs/cryptowalkthru.csproj index ea04b9696d965..684b96a0d38f6 100644 --- a/samples/snippets/csharp/VS_Snippets_CLR/CryptoWalkThru/cs/cryptowalkthru.csproj +++ b/samples/snippets/csharp/VS_Snippets_CLR/CryptoWalkThru/cs/cryptowalkthru.csproj @@ -8,6 +8,6 @@ 4 - + \ No newline at end of file From b6ecd4f675bc3619560a27de7ade66702f51e42d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:36:33 +0000 Subject: [PATCH 09/24] Bump coverlet.collector Bumps [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 3.1.2 to 3.2.0. - [Release notes](https://github.com/coverlet-coverage/coverlet/releases) - [Commits](https://github.com/coverlet-coverage/coverlet/commits/v3.2.0) --- updated-dependencies: - dependency-name: coverlet.collector dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../concepts/linq/LinqSamples.Test/LinqSamples.Test.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/csharp/concepts/linq/LinqSamples.Test/LinqSamples.Test.csproj b/samples/snippets/csharp/concepts/linq/LinqSamples.Test/LinqSamples.Test.csproj index aed99a8884e6a..a79a3bae1cb7b 100644 --- a/samples/snippets/csharp/concepts/linq/LinqSamples.Test/LinqSamples.Test.csproj +++ b/samples/snippets/csharp/concepts/linq/LinqSamples.Test/LinqSamples.Test.csproj @@ -14,7 +14,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all From 7c2ea341171b21e76da6362235d752094a158688 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:36:33 +0000 Subject: [PATCH 10/24] Bump System.Linq.Dynamic.Core Bumps [System.Linq.Dynamic.Core](https://github.com/zzzprojects/System.Linq.Dynamic.Core) from 1.2.20 to 1.2.21. - [Release notes](https://github.com/zzzprojects/System.Linq.Dynamic.Core/releases) - [Changelog](https://github.com/zzzprojects/System.Linq.Dynamic.Core/blob/master/CHANGELOG.md) - [Commits](https://github.com/zzzprojects/System.Linq.Dynamic.Core/compare/v1.2.20...v1.2.21) --- updated-dependencies: - dependency-name: System.Linq.Dynamic.Core dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../dynamic-linq-expression-trees.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/csharp/programming-guide/dynamic-linq-expression-trees/dynamic-linq-expression-trees.csproj b/samples/snippets/csharp/programming-guide/dynamic-linq-expression-trees/dynamic-linq-expression-trees.csproj index c93b6e118ab1e..3c5afc91d7786 100644 --- a/samples/snippets/csharp/programming-guide/dynamic-linq-expression-trees/dynamic-linq-expression-trees.csproj +++ b/samples/snippets/csharp/programming-guide/dynamic-linq-expression-trees/dynamic-linq-expression-trees.csproj @@ -10,7 +10,7 @@ - + From 2a660ab9f8b31c2fe63bb590ed8ea7417b8b12c6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:36:34 +0000 Subject: [PATCH 11/24] Bump System.Linq.Dynamic.Core Bumps [System.Linq.Dynamic.Core](https://github.com/zzzprojects/System.Linq.Dynamic.Core) from 1.2.20 to 1.2.21. - [Release notes](https://github.com/zzzprojects/System.Linq.Dynamic.Core/releases) - [Changelog](https://github.com/zzzprojects/System.Linq.Dynamic.Core/blob/master/CHANGELOG.md) - [Commits](https://github.com/zzzprojects/System.Linq.Dynamic.Core/compare/v1.2.20...v1.2.21) --- updated-dependencies: - dependency-name: System.Linq.Dynamic.Core dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../dynamic-linq-expression-trees.vbproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/visualbasic/programming-guide/dynamic-linq-expression-trees/dynamic-linq-expression-trees.vbproj b/samples/snippets/visualbasic/programming-guide/dynamic-linq-expression-trees/dynamic-linq-expression-trees.vbproj index c13eb8182c6ae..322a3c8bb533a 100644 --- a/samples/snippets/visualbasic/programming-guide/dynamic-linq-expression-trees/dynamic-linq-expression-trees.vbproj +++ b/samples/snippets/visualbasic/programming-guide/dynamic-linq-expression-trees/dynamic-linq-expression-trees.vbproj @@ -9,7 +9,7 @@ - + From cef38b026d9b45648e721a949114b03b1dfc136f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:36:39 +0000 Subject: [PATCH 12/24] Bump Microsoft.Web.WebView2 Bumps Microsoft.Web.WebView2 from 1.0.1370.28 to 1.0.1418.22. --- updated-dependencies: - dependency-name: Microsoft.Web.WebView2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../csharp/WebSiteRatings/WebSiteRatings.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/porting/snippets/upgrade-assistant-wpf-framework/csharp/WebSiteRatings/WebSiteRatings.csproj b/docs/core/porting/snippets/upgrade-assistant-wpf-framework/csharp/WebSiteRatings/WebSiteRatings.csproj index 5650cec5932d9..2eadaba4174a7 100644 --- a/docs/core/porting/snippets/upgrade-assistant-wpf-framework/csharp/WebSiteRatings/WebSiteRatings.csproj +++ b/docs/core/porting/snippets/upgrade-assistant-wpf-framework/csharp/WebSiteRatings/WebSiteRatings.csproj @@ -17,7 +17,7 @@ - + all From 503e6d0b416a256e8e002980bd2dbaa7848114a9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:37:10 +0000 Subject: [PATCH 13/24] Bump Microsoft.NET.Build.Containers in /docs/core/docker/snippets/Worker Bumps [Microsoft.NET.Build.Containers](https://github.com/dotnet/sdk-container-builds) from 0.1.8 to 0.2.7. - [Release notes](https://github.com/dotnet/sdk-container-builds/releases) - [Commits](https://github.com/dotnet/sdk-container-builds/commits) --- updated-dependencies: - dependency-name: Microsoft.NET.Build.Containers dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- docs/core/docker/snippets/Worker/DotNet.ContainerImage.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/docker/snippets/Worker/DotNet.ContainerImage.csproj b/docs/core/docker/snippets/Worker/DotNet.ContainerImage.csproj index db9cf791de0ef..919930c929f78 100644 --- a/docs/core/docker/snippets/Worker/DotNet.ContainerImage.csproj +++ b/docs/core/docker/snippets/Worker/DotNet.ContainerImage.csproj @@ -10,6 +10,6 @@ - + From c5b20d184def17b4b67dd34c9353412dcf4b4c27 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:40:54 +0000 Subject: [PATCH 14/24] Bump Microsoft.Windows.Compatibility Bumps [Microsoft.Windows.Compatibility](https://github.com/dotnet/runtime) from 6.0.0 to 6.0.1. - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](https://github.com/dotnet/runtime/compare/v6.0.0...v6.0.1) --- updated-dependencies: - dependency-name: Microsoft.Windows.Compatibility dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../csharp/StarVoteControl/StarVoteControl.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/porting/snippets/upgrade-assistant-wpf-framework/csharp/StarVoteControl/StarVoteControl.csproj b/docs/core/porting/snippets/upgrade-assistant-wpf-framework/csharp/StarVoteControl/StarVoteControl.csproj index 990c2ece06469..2ef213a2604b7 100644 --- a/docs/core/porting/snippets/upgrade-assistant-wpf-framework/csharp/StarVoteControl/StarVoteControl.csproj +++ b/docs/core/porting/snippets/upgrade-assistant-wpf-framework/csharp/StarVoteControl/StarVoteControl.csproj @@ -12,6 +12,6 @@ all - + \ No newline at end of file From 096b4730b05fd2e7161854429ec4dddcf02ef385 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:40:57 +0000 Subject: [PATCH 15/24] Bump coverlet.collector Bumps [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 3.1.2 to 3.2.0. - [Release notes](https://github.com/coverlet-coverage/coverlet/releases) - [Commits](https://github.com/coverlet-coverage/coverlet/commits/v3.2.0) --- updated-dependencies: - dependency-name: coverlet.collector dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../csharp/MSTest.Project/MSTest.Project.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/testing/snippets/order-unit-tests/csharp/MSTest.Project/MSTest.Project.csproj b/docs/core/testing/snippets/order-unit-tests/csharp/MSTest.Project/MSTest.Project.csproj index cdb2860f0921a..a386f02d0a7cd 100644 --- a/docs/core/testing/snippets/order-unit-tests/csharp/MSTest.Project/MSTest.Project.csproj +++ b/docs/core/testing/snippets/order-unit-tests/csharp/MSTest.Project/MSTest.Project.csproj @@ -11,7 +11,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From 1992f5736297284e14f80c5e3a9521388714c74a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:45:45 +0000 Subject: [PATCH 16/24] Bump coverlet.collector Bumps [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 3.1.2 to 3.2.0. - [Release notes](https://github.com/coverlet-coverage/coverlet/releases) - [Commits](https://github.com/coverlet-coverage/coverlet/commits/v3.2.0) --- updated-dependencies: - dependency-name: coverlet.collector dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../csharp/StringLibraryTest/StringLibraryTest.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/tutorials/snippets/library-with-visual-studio-6-0/csharp/StringLibraryTest/StringLibraryTest.csproj b/docs/core/tutorials/snippets/library-with-visual-studio-6-0/csharp/StringLibraryTest/StringLibraryTest.csproj index e3fb02a7be0f3..4c7f7514d7b72 100644 --- a/docs/core/tutorials/snippets/library-with-visual-studio-6-0/csharp/StringLibraryTest/StringLibraryTest.csproj +++ b/docs/core/tutorials/snippets/library-with-visual-studio-6-0/csharp/StringLibraryTest/StringLibraryTest.csproj @@ -11,7 +11,7 @@ - + From 911a1bebad367a8fcb9e4a4a1555422d5cfeee21 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:45:47 +0000 Subject: [PATCH 17/24] Bump coverlet.collector Bumps [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 3.1.2 to 3.2.0. - [Release notes](https://github.com/coverlet-coverage/coverlet/releases) - [Commits](https://github.com/coverlet-coverage/coverlet/commits/v3.2.0) --- updated-dependencies: - dependency-name: coverlet.collector dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../csharp/XUnit.TestProject/XUnit.Project.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/testing/snippets/order-unit-tests/csharp/XUnit.TestProject/XUnit.Project.csproj b/docs/core/testing/snippets/order-unit-tests/csharp/XUnit.TestProject/XUnit.Project.csproj index 9f48cd063afa6..b34499ad64a1b 100644 --- a/docs/core/testing/snippets/order-unit-tests/csharp/XUnit.TestProject/XUnit.Project.csproj +++ b/docs/core/testing/snippets/order-unit-tests/csharp/XUnit.TestProject/XUnit.Project.csproj @@ -14,7 +14,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive From f601c71020a129b5e18ee8ce39a96296889cae53 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:49:27 +0000 Subject: [PATCH 18/24] Bump coverlet.collector Bumps [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 3.1.2 to 3.2.0. - [Release notes](https://github.com/coverlet-coverage/coverlet/releases) - [Commits](https://github.com/coverlet-coverage/coverlet/commits/v3.2.0) --- updated-dependencies: - dependency-name: coverlet.collector dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../vb/StringLibraryTest/StringLibraryTest.vbproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/tutorials/snippets/library-with-visual-studio/vb/StringLibraryTest/StringLibraryTest.vbproj b/docs/core/tutorials/snippets/library-with-visual-studio/vb/StringLibraryTest/StringLibraryTest.vbproj index aef793b160cba..70ace95594c0e 100644 --- a/docs/core/tutorials/snippets/library-with-visual-studio/vb/StringLibraryTest/StringLibraryTest.vbproj +++ b/docs/core/tutorials/snippets/library-with-visual-studio/vb/StringLibraryTest/StringLibraryTest.vbproj @@ -10,7 +10,7 @@ - + From 2b52afdb0112b4e02a47b8bb469b2977f4a18f9e Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Wed, 2 Nov 2022 10:06:30 -0400 Subject: [PATCH 19/24] Retire the "What's new in C# 8" article (#32101) * import range content Some of the range content from the what's new article needed to move to the appropriate tutorial. Move exploration tutorials * move C# 8 new feature tutorials They're now just features. --- .openpublishing.redirection.csharp.json | 42 +- docs/azure/sdk/pagination.md | 2 +- docs/core/compatibility/index.md | 2 +- docs/core/whats-new/dotnet-core-3-0.md | 10 +- docs/csharp/fundamentals/types/interfaces.md | 2 +- docs/csharp/index.yml | 10 - .../keywords/using-statement.md | 3 +- .../language-reference/operators/await.md | 2 +- .../operators/member-access-operators.md | 4 +- .../operators/null-forgiving.md | 2 +- .../statements/iteration-statements.md | 2 +- docs/csharp/nullable-references.md | 2 +- .../how-to-write-to-a-text-file.md | 4 +- docs/csharp/toc.yml | 22 +- .../default-interface-methods-versions.md | 21 +- .../generate-consume-asynchronous-stream.md | 9 +- .../mixins-with-default-interface-methods.md | 34 +- .../tutorials/nullable-reference-types.md | 23 +- .../tutorials/ranges-indexes.md | 28 +- .../NullableIntroduction.csproj | 4 +- .../snippets/NullableIntroduction/Program.cs | 31 + .../NullableIntroduction/SurveyQuestion.cs | 17 + .../NullableIntroduction/SurveyResponse.cs | 69 +++ .../NullableIntroduction/SurveyRun.cs | 32 ++ .../RangesIndexes/IndicesAndRanges.cs | 198 +++++++ .../snippets/RangesIndexes/Program.cs | 22 + .../RangesIndexes/RangesIndexes.csproj | 10 + .../customer-relationship/ICustomer.cs | 80 +++ .../finished/customer-relationship/IOrder.cs | 7 + .../finished/customer-relationship/Program.cs | 50 ++ .../customer-relationship/SampleCustomer.cs | 37 ++ .../customer-relationship/SampleOrder.cs | 11 + .../customer-relationship.csproj | 11 + .../customer-relationship/ICustomer.cs | 13 + .../starter/customer-relationship/IOrder.cs | 9 + .../starter/customer-relationship/Program.cs | 26 + .../customer-relationship/SampleCustomer.cs | 27 + .../customer-relationship/SampleOrder.cs | 11 + .../customer-relationship.csproj | 4 +- .../finished/IssuePRreport.csproj | 2 +- .../finished/Program.cs | 0 .../start/IssuePRreport.csproj | 2 +- .../start/Program.cs | 0 .../ExtraFancyLight.cs | 0 .../HalogenLight.cs | 0 .../IBlinkingLight.cs | 0 .../ILight.cs | 0 .../ITimerLight.cs | 0 .../LEDLight.cs | 0 .../OverheadLight.cs | 0 .../Program.cs | 0 .../UnusedExampleCode.cs | 0 .../mixins-with-interfaces.csproj | 2 +- docs/csharp/whats-new/csharp-8.md | 531 ------------------ .../whats-new/csharp-version-history.md | 32 +- docs/fsharp/whats-new/fsharp-50.md | 2 +- docs/fsharp/whats-new/fsharp-6.md | 2 +- docs/iot/tutorials/adc.md | 2 +- docs/iot/tutorials/blink-led.md | 2 +- docs/iot/tutorials/lcd-display.md | 2 +- docs/iot/tutorials/temp-sensor.md | 2 +- .../implementing-disposeasync.md | 2 +- .../garbage-collection/using-objects.md | 2 +- .../NullableIntroduction/Program.cs | 40 -- .../NullableIntroduction/SurveyQuestion.cs | 18 - .../NullableIntroduction/SurveyResponse.cs | 73 --- .../NullableIntroduction/SurveyRun.cs | 36 -- .../RangesIndexes/IndicesAndRanges.cs | 202 ------- .../csharp/tutorials/RangesIndexes/Program.cs | 31 - .../RangesIndexes/RangesIndexes.csproj | 8 - .../customer-relationship/ICustomer.cs | 86 --- .../finished/customer-relationship/IOrder.cs | 10 - .../finished/customer-relationship/Program.cs | 61 -- .../customer-relationship/SampleCustomer.cs | 43 -- .../customer-relationship/SampleOrder.cs | 16 - .../customer-relationship.csproj | 10 - .../customer-relationship/ICustomer.cs | 17 - .../starter/customer-relationship/IOrder.cs | 12 - .../starter/customer-relationship/Program.cs | 36 -- .../customer-relationship/SampleCustomer.cs | 31 - .../customer-relationship/SampleOrder.cs | 14 - 81 files changed, 804 insertions(+), 1418 deletions(-) rename docs/csharp/{whats-new => }/tutorials/default-interface-methods-versions.md (80%) rename docs/csharp/{whats-new => }/tutorials/generate-consume-asynchronous-stream.md (97%) rename docs/csharp/{whats-new => }/tutorials/mixins-with-default-interface-methods.md (76%) rename docs/csharp/{whats-new => }/tutorials/nullable-reference-types.md (88%) rename docs/csharp/{whats-new => }/tutorials/ranges-indexes.md (77%) rename {samples/snippets/csharp/NullableIntroduction => docs/csharp/tutorials/snippets}/NullableIntroduction/NullableIntroduction.csproj (62%) create mode 100644 docs/csharp/tutorials/snippets/NullableIntroduction/Program.cs create mode 100644 docs/csharp/tutorials/snippets/NullableIntroduction/SurveyQuestion.cs create mode 100644 docs/csharp/tutorials/snippets/NullableIntroduction/SurveyResponse.cs create mode 100644 docs/csharp/tutorials/snippets/NullableIntroduction/SurveyRun.cs create mode 100644 docs/csharp/tutorials/snippets/RangesIndexes/IndicesAndRanges.cs create mode 100644 docs/csharp/tutorials/snippets/RangesIndexes/Program.cs create mode 100644 docs/csharp/tutorials/snippets/RangesIndexes/RangesIndexes.csproj create mode 100644 docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/ICustomer.cs create mode 100644 docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/IOrder.cs create mode 100644 docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/Program.cs create mode 100644 docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/SampleCustomer.cs create mode 100644 docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/SampleOrder.cs create mode 100644 docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/customer-relationship.csproj create mode 100644 docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/ICustomer.cs create mode 100644 docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/IOrder.cs create mode 100644 docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/Program.cs create mode 100644 docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/SampleCustomer.cs create mode 100644 docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/SampleOrder.cs rename {samples/snippets/csharp/tutorials => docs/csharp/tutorials/snippets}/default-interface-members-versions/starter/customer-relationship/customer-relationship.csproj (58%) rename docs/csharp/{whats-new => }/tutorials/snippets/generate-consume-asynchronous-streams/finished/IssuePRreport.csproj (88%) rename docs/csharp/{whats-new => }/tutorials/snippets/generate-consume-asynchronous-streams/finished/Program.cs (100%) rename docs/csharp/{whats-new => }/tutorials/snippets/generate-consume-asynchronous-streams/start/IssuePRreport.csproj (88%) rename docs/csharp/{whats-new => }/tutorials/snippets/generate-consume-asynchronous-streams/start/Program.cs (100%) rename docs/csharp/{whats-new => }/tutorials/snippets/mixins-with-default-interface-methods/ExtraFancyLight.cs (100%) rename docs/csharp/{whats-new => }/tutorials/snippets/mixins-with-default-interface-methods/HalogenLight.cs (100%) rename docs/csharp/{whats-new => }/tutorials/snippets/mixins-with-default-interface-methods/IBlinkingLight.cs (100%) rename docs/csharp/{whats-new => }/tutorials/snippets/mixins-with-default-interface-methods/ILight.cs (100%) rename docs/csharp/{whats-new => }/tutorials/snippets/mixins-with-default-interface-methods/ITimerLight.cs (100%) rename docs/csharp/{whats-new => }/tutorials/snippets/mixins-with-default-interface-methods/LEDLight.cs (100%) rename docs/csharp/{whats-new => }/tutorials/snippets/mixins-with-default-interface-methods/OverheadLight.cs (100%) rename docs/csharp/{whats-new => }/tutorials/snippets/mixins-with-default-interface-methods/Program.cs (100%) rename docs/csharp/{whats-new => }/tutorials/snippets/mixins-with-default-interface-methods/UnusedExampleCode.cs (100%) rename docs/csharp/{whats-new => }/tutorials/snippets/mixins-with-default-interface-methods/mixins-with-interfaces.csproj (84%) delete mode 100644 docs/csharp/whats-new/csharp-8.md delete mode 100644 samples/snippets/csharp/NullableIntroduction/NullableIntroduction/Program.cs delete mode 100644 samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyQuestion.cs delete mode 100644 samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyResponse.cs delete mode 100644 samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyRun.cs delete mode 100644 samples/snippets/csharp/tutorials/RangesIndexes/IndicesAndRanges.cs delete mode 100644 samples/snippets/csharp/tutorials/RangesIndexes/Program.cs delete mode 100644 samples/snippets/csharp/tutorials/RangesIndexes/RangesIndexes.csproj delete mode 100644 samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/ICustomer.cs delete mode 100644 samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/IOrder.cs delete mode 100644 samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/Program.cs delete mode 100644 samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/SampleCustomer.cs delete mode 100644 samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/SampleOrder.cs delete mode 100644 samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/customer-relationship.csproj delete mode 100644 samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/ICustomer.cs delete mode 100644 samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/IOrder.cs delete mode 100644 samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/Program.cs delete mode 100644 samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/SampleCustomer.cs delete mode 100644 samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/SampleOrder.cs diff --git a/.openpublishing.redirection.csharp.json b/.openpublishing.redirection.csharp.json index d368ca6c03ded..040f56cf1bd99 100644 --- a/.openpublishing.redirection.csharp.json +++ b/.openpublishing.redirection.csharp.json @@ -2736,10 +2736,6 @@ "source_path_from_root": "/docs/csharp/tutorials/exploration/top-level-statements.md", "redirect_url": "/dotnet/csharp/whats-new/tutorials/top-level-statements" }, - { - "source_path_from_root": "/docs/csharp/tutorials/generate-consume-asynchronous-stream.md", - "redirect_url": "/dotnet/csharp/whats-new/tutorials/generate-consume-asynchronous-stream" - }, { "source_path_from_root": "/docs/csharp/tutorials/index.md", "redirect_url": "/dotnet/csharp/fundamentals/tutorials/how-to-display-command-line-arguments" @@ -2804,22 +2800,10 @@ "source_path_from_root": "/docs/csharp/tutorials/microservices.md", "redirect_url": "/dotnet/core/docker/" }, - { - "source_path_from_root": "/docs/csharp/tutorials/mixins-with-default-interface-methods.md", - "redirect_url": "/dotnet/csharp/whats-new/tutorials/mixins-with-default-interface-methods" - }, - { - "source_path_from_root": "/docs/csharp/tutorials/nullable-reference-types.md", - "redirect_url": "/dotnet/csharp/whats-new/tutorials/nullable-reference-types" - }, { "source_path_from_root": "/docs/csharp/tutorials/pattern-matching.md", "redirect_url": "/dotnet/csharp/fundamentals/tutorials/pattern-matching" }, - { - "source_path_from_root": "/docs/csharp/tutorials/ranges-indexes.md", - "redirect_url": "/dotnet/csharp/whats-new/tutorials/ranges-indexes" - }, { "source_path_from_root": "/docs/csharp/tutorials/upgrade-to-nullable-references.md", "redirect_url": "/dotnet/csharp/nullable-migration-strategies" @@ -2834,7 +2818,7 @@ }, { "source_path_from_root": "/docs/csharp/whats-new.md", - "redirect_url": "/dotnet/csharp/whats-new/csharp-10", + "redirect_url": "/dotnet/csharp/whats-new/csharp-11", "redirect_document_id": true }, { @@ -2857,6 +2841,10 @@ "source_path_from_root": "/docs/csharp/whats-new/csharp-7.md", "redirect_url": "/dotnet/csharp/whats-new/csharp-version-history#c-version-70" }, + { + "source_path_from_root": "/docs/csharp/whats-new/csharp-8.md", + "redirect_url": "/dotnet/csharp/whats-new/csharp-version-history#c-version-80" + }, { "source_path_from_root": "/docs/csharp/whats-new/index.md", "redirect_url": "/dotnet/csharp/whats-new/csharp-11", @@ -2865,6 +2853,26 @@ { "source_path_from_root": "/docs/csharp/whats-new/tutorials/upgrade-to-nullable-references.md", "redirect_url": "/dotnet/csharp/nullable-migration-strategies" + }, + { + "source_path_from_root": "/docs/csharp/whats-new/tutorials/default-interface-methods-versions.md", + "redirect_url": "/dotnet/csharp/tutorials/default-interface-methods-versions" + }, + { + "source_path_from_root": "/docs/csharp/whats-new/tutorials/generate-consume-asynchronous-stream.md", + "redirect_url": "/dotnet/csharp/tutorials/generate-consume-asynchronous-stream" + }, + { + "source_path_from_root": "/docs/csharp/whats-new/tutorials/mixins-with-default-interface-methods.md", + "redirect_url": "/dotnet/csharp/tutorials/mixins-with-default-interface-methods" + }, + { + "source_path_from_root": "/docs/csharp/whats-new/tutorials/nullable-reference-types.md", + "redirect_url": "/dotnet/csharp/tutorials/nullable-reference-types" + }, + { + "source_path_from_root": "/docs/csharp/whats-new/tutorials/ranges-indexes.md", + "redirect_url": "/dotnet/csharp/tutorials/ranges-indexes" } ] } diff --git a/docs/azure/sdk/pagination.md b/docs/azure/sdk/pagination.md index e14ca936f7835..4b3b58c1c8cff 100644 --- a/docs/azure/sdk/pagination.md +++ b/docs/azure/sdk/pagination.md @@ -9,7 +9,7 @@ author: IEvangelist # Pagination with the Azure SDK for .NET -In this article, you'll learn how to use the Azure SDK for .NET pagination functionality to work efficiently and productively with large data sets. Pagination is the act of dividing large data sets into pages, making it easier for the consumer to iterate through smaller amounts of data. Starting with C# 8, you can create and consume streams asynchronously using [Asynchronous (async) streams](../../csharp/whats-new/csharp-8.md#asynchronous-streams). Async streams are based on the interface. The Azure SDK for .NET exposes an implementation of `IAsyncEnumerable` with its `AsyncPageable` class. +In this article, you'll learn how to use the Azure SDK for .NET pagination functionality to work efficiently and productively with large data sets. Pagination is the act of dividing large data sets into pages, making it easier for the consumer to iterate through smaller amounts of data. Starting with C# 8, you can create and consume streams asynchronously using [Asynchronous (async) streams](../../csharp/language-reference/statements/iteration-statements.md#await-foreach). Async streams are based on the interface. The Azure SDK for .NET exposes an implementation of `IAsyncEnumerable` with its `AsyncPageable` class. All of the samples in this article rely on the following NuGet packages: diff --git a/docs/core/compatibility/index.md b/docs/core/compatibility/index.md index 5eb31363dc1d1..8e9db9099e0e3 100644 --- a/docs/core/compatibility/index.md +++ b/docs/core/compatibility/index.md @@ -127,7 +127,7 @@ Changes in this category modify the public surface area of a type. Most of the c - ❌ **DISALLOWED: Adding a member to an interface** - If you [provide an implementation](../../csharp/whats-new/tutorials/default-interface-methods-versions.md), adding a new member to an existing interface won't necessarily result in compile failures in downstream assemblies. However, not all languages support default interface members (DIMs). Also, in some scenarios, the runtime can't decide which default interface member to invoke. For these reasons, adding a member to an existing interface is considered a breaking change. + If you [provide an implementation](../../csharp/tutorials/default-interface-methods-versions.md), adding a new member to an existing interface won't necessarily result in compile failures in downstream assemblies. However, not all languages support default interface members (DIMs). Also, in some scenarios, the runtime can't decide which default interface member to invoke. For these reasons, adding a member to an existing interface is considered a breaking change. - ❌ **DISALLOWED: Changing the value of a public constant or enumeration member** diff --git a/docs/core/whats-new/dotnet-core-3-0.md b/docs/core/whats-new/dotnet-core-3-0.md index 0702efc328432..e1cf685a340df 100644 --- a/docs/core/whats-new/dotnet-core-3-0.md +++ b/docs/core/whats-new/dotnet-core-3-0.md @@ -22,12 +22,12 @@ For more information about the release, see the [.NET Core 3.0 announcement](htt ## Language improvements C# 8.0 -C# 8.0 is also part of this release, which includes the [nullable reference types](../../csharp/language-reference/builtin-types/nullable-reference-types.md) feature, async streams, and more patterns. For more information about C# 8.0 features, see [What's new in C# 8.0](../../csharp/whats-new/csharp-8.md). +C# 8.0 is also part of this release, which includes the [nullable reference types](../../csharp/language-reference/builtin-types/nullable-reference-types.md) feature, async streams, and more patterns. For more information about C# 8.0 features, see [What's new in C# 8.0](../../csharp/whats-new/csharp-version-history.md#c-version-80). Tutorials related to C# 8.0 language features: -- [Tutorial: Express your design intent more clearly with nullable and non-nullable reference types](../../csharp/whats-new/tutorials/nullable-reference-types.md) -- [Tutorial: Generate and consume async streams using C# 8.0 and .NET Core 3.0](../../csharp/whats-new/tutorials/generate-consume-asynchronous-stream.md) +- [Tutorial: Express your design intent more clearly with nullable and non-nullable reference types](../../csharp/tutorials/nullable-reference-types.md) +- [Tutorial: Generate and consume async streams using C# 8.0 and .NET Core 3.0](../../csharp/tutorials/generate-consume-asynchronous-stream.md) - [Tutorial: Use pattern matching to build type-driven and data-driven algorithms](../../csharp/fundamentals/tutorials/pattern-matching.md) Language enhancements were added to support the following API features detailed below: @@ -443,7 +443,7 @@ There's also the type, which co var slice = a[i1..i2]; // { 3, 4, 5 } ``` -For more information, see the [ranges and indices tutorial](../../csharp/whats-new/tutorials/ranges-indexes.md). +For more information, see the [ranges and indices tutorial](../../csharp/tutorials/ranges-indexes.md). ### Async streams @@ -463,7 +463,7 @@ async IAsyncEnumerable GetBigResultsAsync() In addition to being able to `await foreach`, you can also create async iterators, for example, an iterator that returns an `IAsyncEnumerable/IAsyncEnumerator` that you can both `await` and `yield` in. For objects that need to be disposed, you can use `IAsyncDisposable`, which various BCL types implement, such as `Stream` and `Timer`. -For more information, see the [async streams tutorial](../../csharp/whats-new/tutorials/generate-consume-asynchronous-stream.md). +For more information, see the [async streams tutorial](../../csharp/tutorials/generate-consume-asynchronous-stream.md). ### IEEE Floating-point diff --git a/docs/csharp/fundamentals/types/interfaces.md b/docs/csharp/fundamentals/types/interfaces.md index 67ab5c9f1fed6..2ea9c1cb3eb8c 100644 --- a/docs/csharp/fundamentals/types/interfaces.md +++ b/docs/csharp/fundamentals/types/interfaces.md @@ -48,6 +48,6 @@ A base class can also implement interface members by using virtual members. In t An interface has the following properties: - In C# versions earlier than 8.0, an interface is like an abstract base class with only abstract members. A class or struct that implements the interface must implement all its members. -- Beginning with C# 8.0, an interface may define default implementations for some or all of its members. A class or struct that implements the interface doesn't have to implement members that have default implementations. For more information, see [default interface methods](../../whats-new/tutorials/default-interface-methods-versions.md). +- Beginning with C# 8.0, an interface may define default implementations for some or all of its members. A class or struct that implements the interface doesn't have to implement members that have default implementations. For more information, see [default interface methods](../../tutorials/default-interface-methods-versions.md). - An interface can't be instantiated directly. Its members are implemented by any class or struct that implements the interface. - A class or struct can implement multiple interfaces. A class can inherit a base class and also implement one or more interfaces. diff --git a/docs/csharp/index.yml b/docs/csharp/index.yml index 71c7823a4825d..d1b8ae340d633 100644 --- a/docs/csharp/index.yml +++ b/docs/csharp/index.yml @@ -128,16 +128,6 @@ landingContent: url: whats-new/tutorials/top-level-statements.md - text: Explore new patterns url: whats-new/tutorials/patterns-objects.md - - text: Safely update interfaces - url: whats-new/tutorials/default-interface-methods-versions.md - - text: Create mixins with interfaces - url: whats-new/tutorials/mixins-with-default-interface-methods.md - - text: Explore indexes and ranges - url: whats-new/tutorials/ranges-indexes.md - - text: Nullable reference types - url: whats-new/tutorials/nullable-reference-types.md - - text: Explore async streams - url: whats-new/tutorials/generate-consume-asynchronous-stream.md - text: Write a custom string interpolation handler url: whats-new/tutorials/interpolated-string-handler.md - linkListType: reference diff --git a/docs/csharp/language-reference/keywords/using-statement.md b/docs/csharp/language-reference/keywords/using-statement.md index b10fc15cf276d..5e3d030b13f11 100644 --- a/docs/csharp/language-reference/keywords/using-statement.md +++ b/docs/csharp/language-reference/keywords/using-statement.md @@ -10,7 +10,7 @@ ms.assetid: afc355e6-f0b9-4240-94dd-0d93f17d9fc3 --- # using statement (C# Reference) -Provides a convenient syntax that ensures the correct use of objects. The `using` statement ensures the correct use of objects. +The `using` statement provides a convenient syntax that ensures the correct use of objects. The `await using` statement ensures the correct use of objects. The language supports asynchronous disposable types that implement the interface. ## Example @@ -65,3 +65,4 @@ For more information, see [The using statement](~/_csharpstandard/standard/state - [Using objects that implement IDisposable](../../../standard/garbage-collection/using-objects.md) - [IDisposable interface](xref:System.IDisposable) - [using statement in C# 8.0](~/_csharplang/proposals/csharp-8.0/using.md) +- [Implement a DisposeAsync method](../../../standard/garbage-collection/implementing-disposeasync.md) article. diff --git a/docs/csharp/language-reference/operators/await.md b/docs/csharp/language-reference/operators/await.md index bbe2f6f9737e9..c9616e3ed4146 100644 --- a/docs/csharp/language-reference/operators/await.md +++ b/docs/csharp/language-reference/operators/await.md @@ -50,4 +50,4 @@ For more information, see the [Await expressions](~/_csharpstandard/standard/exp - [Task asynchronous programming model](../../programming-guide/concepts/async/task-asynchronous-programming-model.md) - [Asynchronous programming](../../async.md) - [Walkthrough: accessing the Web by using async and await](../../programming-guide/concepts/async/index.md) -- [Tutorial: Generate and consume async streams](../../whats-new/tutorials/generate-consume-asynchronous-stream.md) +- [Tutorial: Generate and consume async streams](../../tutorials/generate-consume-asynchronous-stream.md) diff --git a/docs/csharp/language-reference/operators/member-access-operators.md b/docs/csharp/language-reference/operators/member-access-operators.md index c97cf0a4b5337..6655c22aa2302 100644 --- a/docs/csharp/language-reference/operators/member-access-operators.md +++ b/docs/csharp/language-reference/operators/member-access-operators.md @@ -188,7 +188,7 @@ The `^` operator indicates the element position from the end of a sequence. For As the preceding example shows, expression `^e` is of the type. In expression `^e`, the result of `e` must be implicitly convertible to `int`. -You can also use the `^` operator with the [range operator](#range-operator-) to create a range of indices. For more information, see [Indices and ranges](../../whats-new/tutorials/ranges-indexes.md). +You can also use the `^` operator with the [range operator](#range-operator-) to create a range of indices. For more information, see [Indices and ranges](../../tutorials/ranges-indexes.md). ## Range operator .. @@ -226,7 +226,7 @@ The following example demonstrates the effect of using all the ranges presented :::code language="csharp" source="snippets/shared/MemberAccessOperators.cs" id="RangesAllPossible"::: -For more information, see [Indices and ranges](../../whats-new/tutorials/ranges-indexes.md). +For more information, see [Indices and ranges](../../tutorials/ranges-indexes.md). ## Operator overloadability diff --git a/docs/csharp/language-reference/operators/null-forgiving.md b/docs/csharp/language-reference/operators/null-forgiving.md index 5a50e8864c84a..57815f29becf7 100644 --- a/docs/csharp/language-reference/operators/null-forgiving.md +++ b/docs/csharp/language-reference/operators/null-forgiving.md @@ -49,4 +49,4 @@ For more information, see [The null-forgiving operator](~/_csharplang/proposals/ - [Remove unnecessary suppression operator (style rule IDE0080)](../../../fundamentals/code-analysis/style-rules/ide0080.md) - [C# reference](../index.md) - [C# operators and expressions](index.md) -- [Tutorial: Design with nullable reference types](../../whats-new/tutorials/nullable-reference-types.md) +- [Tutorial: Design with nullable reference types](../../tutorials/nullable-reference-types.md) diff --git a/docs/csharp/language-reference/statements/iteration-statements.md b/docs/csharp/language-reference/statements/iteration-statements.md index 79d77191fd0d7..cad4d0211d1c2 100644 --- a/docs/csharp/language-reference/statements/iteration-statements.md +++ b/docs/csharp/language-reference/statements/iteration-statements.md @@ -112,7 +112,7 @@ You can also use the `await foreach` statement with an instance of any type that - A type has the public parameterless `GetAsyncEnumerator` method. That method can be a type's [extension method](../../programming-guide/classes-and-structs/extension-methods.md). - The return type of the `GetAsyncEnumerator` method has the public `Current` property and the public parameterless `MoveNextAsync` method whose return type is [`Task`](xref:System.Threading.Tasks.Task%601), [`ValueTask`](xref:System.Threading.Tasks.ValueTask%601), or any other awaitable type whose awaiter's `GetResult` method returns a `bool` value. -By default, stream elements are processed in the captured context. If you want to disable capturing of the context, use the extension method. For more information about synchronization contexts and capturing the current context, see [Consuming the Task-based asynchronous pattern](../../../standard/asynchronous-programming-patterns/consuming-the-task-based-asynchronous-pattern.md). For more information about asynchronous streams, see the [Asynchronous streams](../../whats-new/csharp-8.md#asynchronous-streams) section of the [What's new in C# 8.0](../../whats-new/csharp-8.md) article. +By default, stream elements are processed in the captured context. If you want to disable capturing of the context, use the extension method. For more information about synchronization contexts and capturing the current context, see [Consuming the Task-based asynchronous pattern](../../../standard/asynchronous-programming-patterns/consuming-the-task-based-asynchronous-pattern.md). For more information about asynchronous streams, see the [Asynchronous streams tutorial](../../tutorials/generate-consume-asynchronous-stream.md). ### Type of an iteration variable diff --git a/docs/csharp/nullable-references.md b/docs/csharp/nullable-references.md index 8a8d352d95d67..2bbc3d7fa790e 100644 --- a/docs/csharp/nullable-references.md +++ b/docs/csharp/nullable-references.md @@ -340,5 +340,5 @@ In the preceding example, the declaration of the array shows it holds non-nullab - [Nullable reference types proposal](~/_csharplang/proposals/csharp-8.0/nullable-reference-types.md) - [Draft nullable reference types specification](~/_csharplang/proposals/csharp-9.0/nullable-reference-types-specification.md) - [Unconstrained type parameter annotations](~/_csharplang/proposals/csharp-9.0/unconstrained-type-parameter-annotations.md) -- [Intro to nullable references tutorial](whats-new/tutorials/nullable-reference-types.md) +- [Intro to nullable references tutorial](tutorials/nullable-reference-types.md) - [**Nullable** (C# Compiler option)](language-reference/compiler-options/language.md#nullable) diff --git a/docs/csharp/programming-guide/file-system/how-to-write-to-a-text-file.md b/docs/csharp/programming-guide/file-system/how-to-write-to-a-text-file.md index 9b5646d9b6c50..3825e0cba1bac 100644 --- a/docs/csharp/programming-guide/file-system/how-to-write-to-a-text-file.md +++ b/docs/csharp/programming-guide/file-system/how-to-write-to-a-text-file.md @@ -52,7 +52,7 @@ The preceding source code example: The preceding source code example: - Instantiates a string array with three values. -- Instantiates a with a file path of *WriteLines2.txt* as a [using declaration](../../whats-new/csharp-8.md#using-declarations). +- Instantiates a with a file path of *WriteLines2.txt* as a [using declaration](../../language-reference/keywords/using-statement.md). - Iterates through all the lines. - Conditionally awaits a call to , which writes the line to the file when the line doesn't contain `"Second"`. @@ -63,7 +63,7 @@ The preceding source code example: The preceding source code example: - Instantiates a string array with three values. -- Instantiates a with a file path of *WriteLines2.txt* as a [using declaration](../../whats-new/csharp-8.md#using-declarations), passing in `true` to append. +- Instantiates a with a file path of *WriteLines2.txt* as a [using declaration](../../language-reference/keywords/using-statement.md), passing in `true` to append. - Awaits a call to , which writes the string to the file as an appended line. ## Exceptions diff --git a/docs/csharp/toc.yml b/docs/csharp/toc.yml index 42951522f1fc4..e82b1f0428813 100644 --- a/docs/csharp/toc.yml +++ b/docs/csharp/toc.yml @@ -157,8 +157,6 @@ items: href: whats-new/csharp-10.md - name: C# 9.0 href: whats-new/csharp-9.md - - name: C# 8.0 - href: whats-new/csharp-8.md - name: Breaking changes in earlier versions href: whats-new/breaking-changes.md - name: C# Version History @@ -177,20 +175,20 @@ items: href: whats-new/tutorials/top-level-statements.md - name: Explore patterns in objects href: whats-new/tutorials/patterns-objects.md - - name: Safely update interfaces with default interface methods - href: whats-new/tutorials/default-interface-methods-versions.md - - name: Create mixin functionality with default interface methods - href: whats-new/tutorials/mixins-with-default-interface-methods.md - - name: Explore indexes and ranges - href: whats-new/tutorials/ranges-indexes.md - - name: Work with nullable reference types - href: whats-new/tutorials/nullable-reference-types.md - - name: Generate and consume asynchronous streams - href: whats-new/tutorials/generate-consume-asynchronous-stream.md - name: Write a custom string interpolation handler href: whats-new/tutorials/interpolated-string-handler.md - name: Tutorials items: + - name: Safely update interfaces with default interface methods + href: tutorials/default-interface-methods-versions.md + - name: Create mixin functionality with default interface methods + href: tutorials/mixins-with-default-interface-methods.md + - name: Explore indexes and ranges + href: tutorials/ranges-indexes.md + - name: Work with nullable reference types + href: tutorials/nullable-reference-types.md + - name: Generate and consume asynchronous streams + href: tutorials/generate-consume-asynchronous-stream.md - name: Explore string interpolation - interactive href: tutorials/exploration/interpolated-strings.yml - name: Explore string interpolation - in your environment diff --git a/docs/csharp/whats-new/tutorials/default-interface-methods-versions.md b/docs/csharp/tutorials/default-interface-methods-versions.md similarity index 80% rename from docs/csharp/whats-new/tutorials/default-interface-methods-versions.md rename to docs/csharp/tutorials/default-interface-methods-versions.md index 722980a184d1a..da1eaa2f26b8d 100644 --- a/docs/csharp/whats-new/tutorials/default-interface-methods-versions.md +++ b/docs/csharp/tutorials/default-interface-methods-versions.md @@ -1,9 +1,8 @@ --- title: Safely update interfaces using default interface methods in C# description: This advanced tutorial explores how you can safely add new capabilities to existing interface definitions without breaking all classes and structs that implement that interface. -ms.date: 05/06/2019 +ms.date: 11/01/2022 ms.technology: csharp-advanced-concepts -ms.custom: mvc --- # Tutorial: Update interfaces with default interface methods @@ -25,11 +24,11 @@ You’ll need to set up your machine to run .NET, including the C# compiler. The This tutorial starts with version 1 of a customer relationship library. You can get the starter application on our [samples repo on GitHub](https://github.com/dotnet/samples/tree/main/csharp/tutorials/default-interface-members-versions/starter/customer-relationship). The company that built this library intended customers with existing applications to adopt their library. They provided minimal interface definitions for users of their library to implement. Here's the interface definition for a customer: -[!code-csharp[InitialCustomerInterface](~/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/ICustomer.cs?name=SnippetICustomerVersion1)] +:::code language="csharp" source="./snippets/default-interface-members-versions/starter/customer-relationship/ICustomer.cs" id="SnippetICustomerVersion1"::: They defined a second interface that represents an order: -[!code-csharp[InitialOrderInterface](~/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/IOrder.cs?name=SnippetIorderVersion1)] +:::code language="csharp" source="./snippets/default-interface-members-versions/starter/customer-relationship/IOrder.cs" id="SnippetIorderVersion1"::: From those interfaces, the team could build a library for their users to create a better experience for their customers. Their goal was to create a deeper relationship with existing customers and improve their relationships with new customers. @@ -47,15 +46,15 @@ The upgrade should provide the functionality to set two properties: the number o First, add the new method to the interface, including the body of the method: -[!code-csharp[InitialOrderInterface](~/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/ICustomer.cs?name=SnippetLoyaltyDiscountVersionOne)] +:::code language="csharp" source="./snippets/default-interface-members-versions/finished/customer-relationship/ICustomer.cs" id="SnippetLoyaltyDiscountVersionOne"::: The library author wrote a first test to check the implementation: -[!code-csharp[TestDefaultImplementation](~/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/Program.cs?name=SnippetTestDefaultImplementation)] +:::code language="csharp" source="./snippets/default-interface-members-versions/finished/customer-relationship/Program.cs" id="SnippetTestDefaultImplementation"::: Notice the following portion of the test: -[!code-csharp[TestDefaultImplementation](~/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/Program.cs?name=SnippetHighlightCast)] +:::code language="csharp" source="./snippets/default-interface-members-versions/finished/customer-relationship/Program.cs" id="SnippetHighlightCast"::: That cast from `SampleCustomer` to `ICustomer` is necessary. The `SampleCustomer` class doesn't need to provide an implementation for `ComputeLoyaltyDiscount`; that's provided by the `ICustomer` interface. However, the `SampleCustomer` class doesn't inherit members from its interfaces. That rule hasn't changed. In order to call any method declared and implemented in the interface, the variable must be the type of the interface, `ICustomer` in this example. @@ -63,13 +62,13 @@ That cast from `SampleCustomer` to `ICustomer` is necessary. The `SampleCustomer That's a good start. But, the default implementation is too restrictive. Many consumers of this system may choose different thresholds for number of purchases, a different length of membership, or a different percentage discount. You can provide a better upgrade experience for more customers by providing a way to set those parameters. Let's add a static method that sets those three parameters controlling the default implementation: -[!code-csharp[VersionTwoImplementation](~/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/ICustomer.cs?name=SnippetLoyaltyDiscountVersionTwo)] +:::code language="csharp" source="./snippets/default-interface-members-versions/finished/customer-relationship/ICustomer.cs" id="SnippetLoyaltyDiscountVersionTwo"::: There are many new language capabilities shown in that small code fragment. Interfaces can now include static members, including fields and methods. Different access modifiers are also enabled. The additional fields are private, the new method is public. Any of the modifiers are allowed on interface members. Applications that use the general formula for computing the loyalty discount, but different parameters, don't need to provide a custom implementation; they can set the arguments through a static method. For example, the following code sets a "customer appreciation" that rewards any customer with more than one month's membership: -[!code-csharp[SetLoyaltyThresholds](~/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/Program.cs?name=SnippetSetLoyaltyThresholds)] +:::code language="csharp" source="./snippets/default-interface-members-versions/finished/customer-relationship/Program.cs" id="SnippetSetLoyaltyThresholds"::: ## Extend the default implementation @@ -77,11 +76,11 @@ The code you've added so far has provided a convenient implementation for those Consider a startup that wants to attract new customers. They offer a 50% discount off a new customer's first order. Otherwise, existing customers get the standard discount. The library author needs to move the default implementation into a `protected static` method so that any class implementing this interface can reuse the code in their implementation. The default implementation of the interface member calls this shared method as well: -[!code-csharp[VersionTwoImplementation](~/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/ICustomer.cs?name=SnippetFinalVersion)] +:::code language="csharp" source="./snippets/default-interface-members-versions/finished/customer-relationship/ICustomer.cs" id="SnippetFinalVersion"::: In an implementation of a class that implements this interface, the override can call the static helper method, and extend that logic to provide the "new customer" discount: -[!code-csharp[VersionTwoImplementation](~/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/SampleCustomer.cs?name=SnippetOverrideAndExtend)] +:::code language="csharp" source="./snippets/default-interface-members-versions/finished/customer-relationship/SampleCustomer.cs" id="SnippetOverrideAndExtend"::: You can see the entire finished code in our [samples repo on GitHub](https://github.com/dotnet/samples/tree/main/csharp/tutorials/default-interface-members-versions/finished/customer-relationship). You can get the starter application on our [samples repo on GitHub](https://github.com/dotnet/samples/tree/main/csharp/tutorials/default-interface-members-versions/starter/customer-relationship). diff --git a/docs/csharp/whats-new/tutorials/generate-consume-asynchronous-stream.md b/docs/csharp/tutorials/generate-consume-asynchronous-stream.md similarity index 97% rename from docs/csharp/whats-new/tutorials/generate-consume-asynchronous-stream.md rename to docs/csharp/tutorials/generate-consume-asynchronous-stream.md index dd35eb810679e..e77a6c811c80e 100644 --- a/docs/csharp/whats-new/tutorials/generate-consume-asynchronous-stream.md +++ b/docs/csharp/tutorials/generate-consume-asynchronous-stream.md @@ -1,9 +1,8 @@ --- title: Generate and consume async streams description: This advanced tutorial shows how to generate and consume async streams. Async streams provide a more natural way to work with sequences of data that may be generated asynchronously. -ms.date: 02/10/2019 +ms.date: 11/01/2022 ms.technology: csharp-async -ms.custom: mvc --- # Tutorial: Generate and consume async streams using C# and .NET @@ -36,7 +35,7 @@ This tutorial assumes you're familiar with C# and .NET, including either Visual ## Run the starter application -You can get the code for the starter application used in this tutorial from the [dotnet/docs](https://github.com/dotnet/docs) repository in the [csharp/whats-new/tutorials](https://github.com/dotnet/docs/tree/main/docs/csharp/whats-new/tutorials/snippets/generate-consume-asynchronous-streams/start) folder. +You can get the code for the starter application used in this tutorial from the [dotnet/docs](https://github.com/dotnet/docs) repository in the [csharp/whats-new/tutorials](https://github.com/dotnet/docs/tree/main/docs/csharp/tutorials/snippets/generate-consume-asynchronous-streams/start) folder. The starter application is a console application that uses the [GitHub GraphQL](https://developer.github.com/v4/) interface to retrieve recent issues written in the [dotnet/docs](https://github.com/dotnet/docs) repository. Start by looking at the following code for the starter app `Main` method: @@ -126,7 +125,7 @@ try } ``` -By default, stream elements are processed in the captured context. If you want to disable capturing of the context, use the extension method. For more information about synchronization contexts and capturing the current context, see the article on [consuming the Task-based asynchronous pattern](../../../standard/asynchronous-programming-patterns/consuming-the-task-based-asynchronous-pattern.md). +By default, stream elements are processed in the captured context. If you want to disable capturing of the context, use the extension method. For more information about synchronization contexts and capturing the current context, see the article on [consuming the Task-based asynchronous pattern](../../standard/asynchronous-programming-patterns/consuming-the-task-based-asynchronous-pattern.md). Async streams support cancellation using the same protocol as other `async` methods. You would modify the signature for the async iterator method as follows to support cancellation: @@ -138,7 +137,7 @@ You use another extension method, provide the implementation for any sequence to be the source of a LINQ query. +One way you can implement behavior that appears as part of an interface is to define [extension methods](../programming-guide/classes-and-structs/extension-methods.md) that provide the default behavior. Interfaces declare a minimum set of members while providing a greater surface area for any class that implements that interface. For example, the extension methods in provide the implementation for any sequence to be the source of a LINQ query. Extension methods are resolved at compile time, using the declared type of the variable. Classes that implement the interface can provide a better implementation for any extension method. Variable declarations must match the implementing type to enable the compiler to choose that implementation. When the compile-time type matches the interface, method calls resolve to the extension method. Another concern with extension methods is that those methods are accessible wherever the class containing the extension methods is accessible. Classes cannot declare if they should or should not provide features declared in extension methods. -You can declare the default implementations as interface methods. Then, every class automatically uses the default implementation. Any class that can provide a better implementation can override the interface method definition with a better algorithm. In one sense, this technique sounds similar to how you could use [extension methods](../../programming-guide/classes-and-structs/extension-methods.md). +You can declare the default implementations as interface methods. Then, every class automatically uses the default implementation. Any class that can provide a better implementation can override the interface method definition with a better algorithm. In one sense, this technique sounds similar to how you could use [extension methods](../programming-guide/classes-and-structs/extension-methods.md). In this article, you'll learn how default interface implementations enable new scenarios. @@ -47,21 +47,21 @@ Let's create the code to demonstrate these differences. Start by creating the interface that defines the behavior for all lights: -[!code-csharp[Declare base interface](./snippets/mixins-with-default-interface-methods/UnusedExampleCode.cs?name=SnippetILightInterfaceV1)] +:::code language="csharp" source="./snippets/mixins-with-default-interface-methods/UnusedExampleCode.cs" id="SnippetILightInterfaceV1"::: A basic overhead light fixture might implement this interface as shown in the following code: -[!code-csharp[First overhead light](./snippets/mixins-with-default-interface-methods/UnusedExampleCode.cs?name=SnippetOverheadLightV1)] +:::code language="csharp" source="./snippets/mixins-with-default-interface-methods/UnusedExampleCode.cs" id="SnippetOverheadLightV1"::: In this tutorial, the code doesn't drive IoT devices, but emulates those activities by writing messages to the console. You can explore the code without automating your house. Next, let's define the interface for a light that can automatically turn off after a timeout: -[!code-csharp[pure Timer interface](./snippets/mixins-with-default-interface-methods/UnusedExampleCode.cs?name=SnippetPureTimerInterface)] +:::code language="csharp" source="./snippets/mixins-with-default-interface-methods/UnusedExampleCode.cs" id="SnippetPureTimerInterface"::: You could add a basic implementation to the overhead light, but a better solution is to modify this interface definition to provide a `virtual` default implementation: -[!code-csharp[Timer interface](./snippets/mixins-with-default-interface-methods/ITimerLight.cs?name=SnippetTimerLightFinal)] +:::code language="csharp" source="./snippets/mixins-with-default-interface-methods/ITimerLight.cs" id="SnippetTimerLightFinal"::: By adding that change, the `OverheadLight` class can implement the timer function by declaring support for the interface: @@ -71,7 +71,7 @@ public class OverheadLight : ITimerLight { } A different light type may support a more sophisticated protocol. It can provide its own implementation for `TurnOnFor`, as shown in the following code: -[!code-csharp[Override the timer function](./snippets/mixins-with-default-interface-methods/HalogenLight.cs?name=SnippetHalogenLight)] +:::code language="csharp" source="./snippets/mixins-with-default-interface-methods/HalogenLight.cs" id="SnippetHalogenLight"::: Unlike overriding virtual class methods, the declaration of `TurnOnFor` in the `HalogenLight` class does not use the `override` keyword. @@ -79,41 +79,41 @@ Unlike overriding virtual class methods, the declaration of `TurnOnFor` in the ` The advantages of default interface methods become clearer as you introduce more advanced capabilities. Using interfaces enables you to mix and match capabilities. It also enables each class author to choose between the default implementation and a custom implementation. Let's add an interface with a default implementation for a blinking light: -[!code-csharp[Define the blinking light interface](./snippets/mixins-with-default-interface-methods/IBlinkingLight.cs?name=SnippetBlinkingLight)] +:::code language="csharp" source="./snippets/mixins-with-default-interface-methods/IBlinkingLight.cs" id="SnippetBlinkingLight"::: The default implementation enables any light to blink. The overhead light can add both timer and blink capabilities using the default implementation: -[!code-csharp[Use the default blink function](./snippets/mixins-with-default-interface-methods/OverheadLight.cs?name=SnippetOverheadLight)] +:::code language="csharp" source="./snippets/mixins-with-default-interface-methods/OverheadLight.cs" id="SnippetOverheadLight"::: A new light type, the `LEDLight` supports both the timer function and the blink function directly. This light style implements both the `ITimerLight` and `IBlinkingLight` interfaces, and overrides the `Blink` method: -[!code-csharp[Override the blink function](./snippets/mixins-with-default-interface-methods/LEDLight.cs?name=SnippetLEDLight)] +:::code language="csharp" source="./snippets/mixins-with-default-interface-methods/LEDLight.cs" id="SnippetLEDLight"::: An `ExtraFancyLight` might support both blink and timer functions directly: -[!code-csharp[Override the blink and timer function](./snippets/mixins-with-default-interface-methods/ExtraFancyLight.cs?name=SnippetExtraFancyLight)] +:::code language="csharp" source="./snippets/mixins-with-default-interface-methods/ExtraFancyLight.cs" id="SnippetExtraFancyLight"::: The `HalogenLight` you created earlier doesn't support blinking. So, don't add the `IBlinkingLight` to the list of its supported interfaces. ## Detect the light types using pattern matching -Next, let's write some test code. You can make use of C#'s [pattern matching](../../fundamentals/functional/pattern-matching.md) feature to determine a light's capabilities by examining which interfaces it supports. The following method exercises the supported capabilities of each light: +Next, let's write some test code. You can make use of C#'s [pattern matching](../fundamentals/functional/pattern-matching.md) feature to determine a light's capabilities by examining which interfaces it supports. The following method exercises the supported capabilities of each light: -[!code-csharp[Test a light's capabilities](./snippets/mixins-with-default-interface-methods/Program.cs?name=SnippetTestLightFunctions)] +:::code language="csharp" source="./snippets/mixins-with-default-interface-methods/Program.cs" id="SnippetTestLightFunctions"::: The following code in your `Main` method creates each light type in sequence and tests that light: -[!code-csharp[Test a light's capabilities](./snippets/mixins-with-default-interface-methods/Program.cs?name=SnippetMainMethod)] +:::code language="csharp" source="./snippets/mixins-with-default-interface-methods/Program.cs" id="SnippetMainMethod"::: ## How the compiler determines best implementation This scenario shows a base interface without any implementations. Adding a method into the `ILight` interface introduces new complexities. The language rules governing default interface methods minimize the effect on the concrete classes that implement multiple derived interfaces. Let's enhance the original interface with a new method to show how that changes its use. Every indicator light can report its power status as an enumerated value: -[!code-csharp[Enumeration for power status](./snippets/mixins-with-default-interface-methods/ILight.cs?name=SnippetPowerStatus)] +:::code language="csharp" source="./snippets/mixins-with-default-interface-methods/ILight.cs" id="SnippetPowerStatus"::: The default implementation assumes no power: -[!code-csharp[Report a default power status](./snippets/mixins-with-default-interface-methods/ILight.cs?name=SnippetILightInterface)] +:::code language="csharp" source="./snippets/mixins-with-default-interface-methods/ILight.cs" id="SnippetILightInterface"::: These changes compile cleanly, even though the `ExtraFancyLight` declares support for the `ILight` interface and both derived interfaces, `ITimerLight` and `IBlinkingLight`. There's only one "closest" implementation declared in the `ILight` interface. Any class that declared an override would become the one "closest" implementation. You saw examples in the preceding classes that overrode the members of other derived interfaces. diff --git a/docs/csharp/whats-new/tutorials/nullable-reference-types.md b/docs/csharp/tutorials/nullable-reference-types.md similarity index 88% rename from docs/csharp/whats-new/tutorials/nullable-reference-types.md rename to docs/csharp/tutorials/nullable-reference-types.md index 26e12df9bdd70..36f45c0a17b2c 100644 --- a/docs/csharp/whats-new/tutorials/nullable-reference-types.md +++ b/docs/csharp/tutorials/nullable-reference-types.md @@ -1,14 +1,13 @@ --- title: Design with nullable reference types description: This advanced tutorial provides an introduction to nullable reference types. You'll learn to express your design intent on when reference values may be null, and have the compiler enforce when they cannot be null. -ms.date: 02/19/2019 +ms.date: 11/01/2022 ms.technology: csharp-null-safety -ms.custom: mvc recommendations: false --- # Tutorial: Express your design intent more clearly with nullable and non-nullable reference types -[Nullable reference types](../../nullable-references.md) complement reference types the same way nullable value types complement value types. You declare a variable to be a **nullable reference type** by appending a `?` to the type. For example, `string?` represents a nullable `string`. You can use these new types to more clearly express your design intent: some variables *must always have a value*, others *may be missing a value*. +[Nullable reference types](../nullable-references.md) complement reference types the same way nullable value types complement value types. You declare a variable to be a **nullable reference type** by appending a `?` to the type. For example, `string?` represents a nullable `string`. You can use these new types to more clearly express your design intent: some variables *must always have a value*, others *may be missing a value*. In this tutorial, you'll learn how to: @@ -104,7 +103,7 @@ namespace NullableIntroduction Because you haven't initialized `QuestionText`, the compiler issues a warning that a non-nullable property hasn't been initialized. Your design requires the question text to be non-null, so you add a constructor to initialize it and the `QuestionType` value as well. The finished class definition looks like the following code: -[!code-csharp[DefineQuestion](~/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyQuestion.cs)] +:::code language="csharp" source="./snippets/NullableIntroduction/SurveyQuestion.cs"::: Adding the constructor removes the warning. The constructor argument is also a non-nullable reference type, so the compiler doesn't issue any warnings. @@ -130,7 +129,7 @@ As before, you must initialize the list object to a non-null value or the compil Switch to *Program.cs* in your editor and replace the contents of `Main` with the following lines of code: -[!code-csharp[AddQuestions](~/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/Program.cs#AddQuestions)] +:::code language="csharp" source="./snippets/NullableIntroduction/Program.cs" id="AddQuestions"::: Because the entire project is in an enabled nullable annotation context, you'll get warnings when you pass `null` to any method expecting a non-nullable reference type. Try it by adding the following line to `Main`: @@ -162,7 +161,7 @@ namespace NullableIntroduction Next, add a `static` method to create new participants by generating a random ID: -[!code-csharp[GenerateRespondents](~/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyResponse.cs#Random)] +:::code language="csharp" source="./snippets/NullableIntroduction/SurveyResponse.cs" id="Random"::: The main responsibility of this class is to generate the responses for a participant to the questions in the survey. This responsibility has a few steps: @@ -171,7 +170,7 @@ The main responsibility of this class is to generate the responses for a partici Add the following code to your `SurveyResponse` class: -[!code-csharp[AnswerSurvey](~/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyResponse.cs#AnswerSurvey)] +:::code language="csharp" source="./snippets/NullableIntroduction/SurveyResponse.cs" id="AnswerSurvey"::: The storage for the survey answers is a `Dictionary?`, indicating that it may be null. You're using the new language feature to declare your design intent, both to the compiler and to anyone reading your code later. If you ever dereference `surveyResponses` without checking for the `null` value first, you'll get a compiler warning. You don't get a warning in the `AnswerSurvey` method because the compiler can determine the `surveyResponses` variable was set to a non-null value above. @@ -179,31 +178,31 @@ Using `null` for missing answers highlights a key point for working with nullabl Next, you need to write the `PerformSurvey` method in the `SurveyRun` class. Add the following code in the `SurveyRun` class: -[!code-csharp[PerformSurvey](~/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyRun.cs#PerformSurvey)] +:::code language="csharp" source="./snippets/NullableIntroduction/SurveyRun.cs" id="PerformSurvey"::: Here again, your choice of a nullable `List?` indicates the response may be null. That indicates the survey hasn't been given to any respondents yet. Notice that respondents are added until enough have consented. The last step to run the survey is to add a call to perform the survey at the end of the `Main` method: -[!code-csharp[RunSurvey](~/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/Program.cs#RunSurvey)] +:::code language="csharp" source="./snippets/NullableIntroduction/Program.cs" id="RunSurvey"::: ## Examine survey responses The last step is to display survey results. You'll add code to many of the classes you've written. This code demonstrates the value of distinguishing nullable and non-nullable reference types. Start by adding the following two expression-bodied members to the `SurveyResponse` class: -[!code-csharp[ReportResponses](~/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyResponse.cs#SurveyStatus)] +:::code language="csharp" source="./snippets/NullableIntroduction/SurveyResponse.cs" id="SurveyStatus"::: Because `surveyResponses` is a nullable reference type, null checks are necessary before de-referencing it. The `Answer` method returns a non-nullable string, so we have to cover the case of a missing answer by using the null-coalescing operator. Next, add these three expression-bodied members to the `SurveyRun` class: -[!code-csharp[ReportResults](~/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyRun.cs#RunReport)] +:::code language="csharp" source="./snippets/NullableIntroduction/SurveyRun.cs" id="RunReport"::: The `AllParticipants` member must take into account that the `respondents` variable might be null, but the return value can't be null. If you change that expression by removing the `??` and the empty sequence that follows, the compiler warns you the method might return `null` and its return signature returns a non-nullable type. Finally, add the following loop at the bottom of the `Main` method: -[!code-csharp[DisplaySurveyResults](~/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/Program.cs#WriteAnswers)] +:::code language="csharp" source="./snippets/NullableIntroduction/Program.cs" id="WriteAnswers"::: You don't need any `null` checks in this code because you've designed the underlying interfaces so that they all return non-nullable reference types. diff --git a/docs/csharp/whats-new/tutorials/ranges-indexes.md b/docs/csharp/tutorials/ranges-indexes.md similarity index 77% rename from docs/csharp/whats-new/tutorials/ranges-indexes.md rename to docs/csharp/tutorials/ranges-indexes.md index 143d094077b51..7502c1b8a0149 100644 --- a/docs/csharp/whats-new/tutorials/ranges-indexes.md +++ b/docs/csharp/tutorials/ranges-indexes.md @@ -1,7 +1,7 @@ --- title: Explore ranges of data using indices and ranges description: This advanced tutorial teaches you to explore data using indices and ranges to examine a continuous range of a sequential data set. -ms.date: 09/16/2022 +ms.date: 11/01/2022 ms.technology: csharp-fundamentals ms.custom: mvc --- @@ -20,6 +20,8 @@ In this tutorial, you'll learn how to: ## Language support for indices and ranges +Indices and ranges provide a succinct syntax for accessing single elements or ranges in a sequence. + This language support relies on two new types and two new operators: - represents an index into a sequence. @@ -47,35 +49,37 @@ string[] words = new string[] You can retrieve the last word with the `^1` index. Add the following code below the initialization: -[!code-csharp[LastIndex](~/samples/snippets/csharp/tutorials/RangesIndexes/IndicesAndRanges.cs#IndicesAndRanges_LastIndex)] +:::code language="csharp" source="snippets/RangesIndexes/IndicesAndRanges.cs" id="SnippetIndicesAndRanges_LastIndex"::: -A range specifies the *start* and *end* of a range. Ranges are exclusive, meaning the *end* isn't included in the range. The range `[0..^0]` represents the entire range, just as `[0..sequence.Length]` represents the entire range. +A range specifies the *start* and *end* of a range. The start of the range is inclusive, but the end of the range is exclusive, meaning the *start* is included in the range but the *end* isn't included in the range. The range `[0..^0]` represents the entire range, just as `[0..sequence.Length]` represents the entire range. The following code creates a subrange with the words "quick", "brown", and "fox". It includes `words[1]` through `words[3]`. The element `words[4]` isn't in the range. -[!code-csharp[Range](~/samples/snippets/csharp/tutorials/RangesIndexes/IndicesAndRanges.cs#IndicesAndRanges_Range)] +:::code language="csharp" source="snippets/RangesIndexes/IndicesAndRanges.cs" id="SnippetIndicesAndRanges_Range"::: The following code returns the range with "lazy" and "dog". It includes `words[^2]` and `words[^1]`. The end index `words[^0]` isn't included. Add the following code as well: -[!code-csharp[LastRange](~/samples/snippets/csharp/tutorials/RangesIndexes/IndicesAndRanges.cs#IndicesAndRanges_LastRange)] +:::code language="csharp" source="snippets/RangesIndexes/IndicesAndRanges.cs" id="SnippetIndicesAndRanges_LastRange"::: The following examples create ranges that are open ended for the start, end, or both: -[!code-csharp[PartialRange](~/samples/snippets/csharp/tutorials/RangesIndexes/IndicesAndRanges.cs#IndicesAndRanges_PartialRanges)] +:::code language="csharp" source="snippets/RangesIndexes/IndicesAndRanges.cs" id="SnippetIndicesAndRanges_PartialRanges"::: You can also declare ranges or indices as variables. The variable can then be used inside the `[` and `]` characters: -[!code-csharp[IndexRangeTypes](~/samples/snippets/csharp/tutorials/RangesIndexes/IndicesAndRanges.cs#IndicesAndRanges_RangeIndexTypes)] +:::code language="csharp" source="snippets/RangesIndexes/IndicesAndRanges.cs" id="SnippetIndicesAndRanges_RangeIndexTypes"::: The following sample shows many of the reasons for those choices. Modify `x`, `y`, and `z` to try different combinations. When you experiment, use values where `x` is less than `y`, and `y` is less than `z` for valid combinations. Add the following code in a new method. Try different combinations: -[!code-csharp[SemanticsExamples](~/samples/snippets/csharp/tutorials/RangesIndexes/IndicesAndRanges.cs#IndicesAndRanges_Semantics)] +:::code language="csharp" source="snippets/RangesIndexes/IndicesAndRanges.cs" id="SnippetIndicesAndRanges_Semantics"::: + +Not only arrays support indices and ranges. You can also use indices and ranges with [string](../language-reference/builtin-types/reference-types.md#the-string-type), , or . ### Implicit range operator expression conversions When using the range operator expression syntax, the compiler implicitly converts the start and end values to an and from them, creates a new instance. The following code shows an example implicit conversion from the range operator expression syntax, and its corresponding explicit alternative: -:::code language="csharp" source="../../../../samples/snippets/csharp/tutorials/RangesIndexes/IndicesAndRanges.cs" id="ImplicitRangeOperatorConversion"::: +:::code language="csharp" source="./snippets/RangesIndexes/IndicesAndRanges.cs" id="ImplicitRangeOperatorConversion"::: > [!IMPORTANT] > Implicit conversions from to throw an when the value is negative. Likewise, the `Index` constructor throws an `ArgumentOutOfRangeException` when the `value` parameter is negative. @@ -84,7 +88,7 @@ When using the range operator expression syntax, the compiler implicitly convert Indexes and ranges provide clear, concise syntax to access a single element or a range of elements in a sequence. An index expression typically returns the type of the elements of a sequence. A range expression typically returns the same sequence type as the source sequence. -Any type that provides an [indexer](../../programming-guide/indexers/index.md) with an or parameter explicitly supports indices or ranges respectively. An indexer that takes a single parameter may return a different sequence type, such as . +Any type that provides an [indexer](../programming-guide/indexers/index.md) with an or parameter explicitly supports indices or ranges respectively. An indexer that takes a single parameter may return a different sequence type, such as . > [!IMPORTANT] > The performance of code using the range operator depends on the type of the sequence operand. @@ -99,7 +103,7 @@ For example, the following .NET types support both indices and ranges: has more nuanced behavior. Single dimension arrays support both indices and ranges. Multi-dimensional arrays don't support indexers or ranges. The indexer for a multi-dimensional array has multiple parameters, not a single parameter. Jagged arrays, also referred to as an array of arrays, support both ranges and indexers. The following example shows how to iterate a rectangular subsection of a jagged array. It iterates the section in the center, excluding the first and last three rows, and the first and last two columns from each selected row: -[!code-csharp[JaggedArrays](~/samples/snippets/csharp/tutorials/RangesIndexes/IndicesAndRanges.cs#IndicesAndRanges_JaggedArrays)] +:::code language="csharp" source="./snippets/RangesIndexes/IndicesAndRanges.cs" id="SnippetIndicesAndRanges_JaggedArrays"::: In all cases, the range operator for allocates an array to store the elements returned. @@ -107,7 +111,7 @@ In all cases, the range operator for allocates an array to s You'll often use ranges and indices when you want to analyze a portion of a larger sequence. The new syntax is clearer in reading exactly what portion of the sequence is involved. The local function `MovingAverage` takes a as its argument. The method then enumerates just that range when calculating the min, max, and average. Try the following code in your project: -[!code-csharp[MovingAverages](~/samples/snippets/csharp/tutorials/RangesIndexes/IndicesAndRanges.cs#IndicesAndRanges_MovingAverage)] +:::code language="csharp" source="./snippets/RangesIndexes/IndicesAndRanges.cs" id="SnippetIndicesAndRanges_MovingAverage"::: ## A Note on Range Indices and Arrays diff --git a/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/NullableIntroduction.csproj b/docs/csharp/tutorials/snippets/NullableIntroduction/NullableIntroduction.csproj similarity index 62% rename from samples/snippets/csharp/NullableIntroduction/NullableIntroduction/NullableIntroduction.csproj rename to docs/csharp/tutorials/snippets/NullableIntroduction/NullableIntroduction.csproj index 78245ceaa1826..feb6b26fad750 100644 --- a/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/NullableIntroduction.csproj +++ b/docs/csharp/tutorials/snippets/NullableIntroduction/NullableIntroduction.csproj @@ -2,9 +2,9 @@ Exe - net6.0 - 8.0 + net7.0 enable + enable diff --git a/docs/csharp/tutorials/snippets/NullableIntroduction/Program.cs b/docs/csharp/tutorials/snippets/NullableIntroduction/Program.cs new file mode 100644 index 0000000000000..57c3d6f1809db --- /dev/null +++ b/docs/csharp/tutorials/snippets/NullableIntroduction/Program.cs @@ -0,0 +1,31 @@ +using NullableIntroduction; + +// +var surveyRun = new SurveyRun(); +surveyRun.AddQuestion(QuestionType.YesNo, "Has your code ever thrown a NullReferenceException?"); +surveyRun.AddQuestion(new SurveyQuestion(QuestionType.Number, "How many times (to the nearest 100) has that happened?")); +surveyRun.AddQuestion(QuestionType.Text, "What is your favorite color?"); +// + +// +surveyRun.PerformSurvey(50); +// + +// +foreach (var participant in surveyRun.AllParticipants) +{ + Console.WriteLine($"Participant: {participant.Id}:"); + if (participant.AnsweredSurvey) + { + for (int i = 0; i < surveyRun.Questions.Count; i++) + { + var answer = participant.Answer(i); + Console.WriteLine($"\t{surveyRun.GetQuestion(i).QuestionText} : {answer}"); + } + } + else + { + Console.WriteLine("\tNo responses"); + } +} +// diff --git a/docs/csharp/tutorials/snippets/NullableIntroduction/SurveyQuestion.cs b/docs/csharp/tutorials/snippets/NullableIntroduction/SurveyQuestion.cs new file mode 100644 index 0000000000000..7b682fc1bfda7 --- /dev/null +++ b/docs/csharp/tutorials/snippets/NullableIntroduction/SurveyQuestion.cs @@ -0,0 +1,17 @@ +namespace NullableIntroduction; + +public enum QuestionType +{ + YesNo, + Number, + Text +} + +public class SurveyQuestion +{ + public string QuestionText { get; } + public QuestionType TypeOfQuestion { get; } + + public SurveyQuestion(QuestionType typeOfQuestion, string text) => + (TypeOfQuestion, QuestionText) = (typeOfQuestion, text); +} diff --git a/docs/csharp/tutorials/snippets/NullableIntroduction/SurveyResponse.cs b/docs/csharp/tutorials/snippets/NullableIntroduction/SurveyResponse.cs new file mode 100644 index 0000000000000..60f07de68462e --- /dev/null +++ b/docs/csharp/tutorials/snippets/NullableIntroduction/SurveyResponse.cs @@ -0,0 +1,69 @@ +namespace NullableIntroduction; + +public class SurveyResponse +{ + // + private static readonly Random randomGenerator = new Random(); + public static SurveyResponse GetRandomId() => new SurveyResponse(randomGenerator.Next()); + // + + public int Id { get; } + + // + public bool AnsweredSurvey => surveyResponses != null; + public string Answer(int index) => surveyResponses?.GetValueOrDefault(index) ?? "No answer"; + // + + public SurveyResponse(int id) => Id = id; + + // + private Dictionary? surveyResponses; + public bool AnswerSurvey(IEnumerable questions) + { + if (ConsentToSurvey()) + { + surveyResponses = new Dictionary(); + int index = 0; + foreach (var question in questions) + { + var answer = GenerateAnswer(question); + if (answer != null) + { + surveyResponses.Add(index, answer); + } + index++; + } + } + return surveyResponses != null; + } + + private bool ConsentToSurvey() => randomGenerator.Next(0, 2) == 1; + + private string? GenerateAnswer(SurveyQuestion question) + { + switch (question.TypeOfQuestion) + { + case QuestionType.YesNo: + int n = randomGenerator.Next(-1, 2); + return (n == -1) ? default : (n == 0) ? "No" : "Yes"; + case QuestionType.Number: + n = randomGenerator.Next(-30, 101); + return (n < 0) ? default : n.ToString(); + case QuestionType.Text: + default: + switch (randomGenerator.Next(0, 5)) + { + case 0: + return default; + case 1: + return "Red"; + case 2: + return "Green"; + case 3: + return "Blue"; + } + return "Red. No, Green. Wait.. Blue... AAARGGGGGHHH!"; + } + } + // +} diff --git a/docs/csharp/tutorials/snippets/NullableIntroduction/SurveyRun.cs b/docs/csharp/tutorials/snippets/NullableIntroduction/SurveyRun.cs new file mode 100644 index 0000000000000..47cf893737dac --- /dev/null +++ b/docs/csharp/tutorials/snippets/NullableIntroduction/SurveyRun.cs @@ -0,0 +1,32 @@ +namespace NullableIntroduction; + +public class SurveyRun +{ + private List surveyQuestions = new List(); + + // + public IEnumerable AllParticipants => (respondents ?? Enumerable.Empty()); + public ICollection Questions => surveyQuestions; + public SurveyQuestion GetQuestion(int index) => surveyQuestions[index]; + // + + public void AddQuestion(QuestionType type, string question) => + AddQuestion(new SurveyQuestion(type, question)); + public void AddQuestion(SurveyQuestion surveyQuestion) => surveyQuestions.Add(surveyQuestion); + + // + private List? respondents; + public void PerformSurvey(int numberOfRespondents) + { + int respondentsConsenting = 0; + respondents = new List(); + while (respondentsConsenting < numberOfRespondents) + { + var respondent = SurveyResponse.GetRandomId(); + if (respondent.AnswerSurvey(surveyQuestions)) + respondentsConsenting++; + respondents.Add(respondent); + } + } + // +} diff --git a/docs/csharp/tutorials/snippets/RangesIndexes/IndicesAndRanges.cs b/docs/csharp/tutorials/snippets/RangesIndexes/IndicesAndRanges.cs new file mode 100644 index 0000000000000..e29cb3af07d8a --- /dev/null +++ b/docs/csharp/tutorials/snippets/RangesIndexes/IndicesAndRanges.cs @@ -0,0 +1,198 @@ +namespace RangesIndexes; + +class IndicesAndRanges +{ + // + private string[] words = new string[] + { + // index from start index from end + "The", // 0 ^9 + "quick", // 1 ^8 + "brown", // 2 ^7 + "fox", // 3 ^6 + "jumped", // 4 ^5 + "over", // 5 ^4 + "the", // 6 ^3 + "lazy", // 7 ^2 + "dog" // 8 ^1 + }; + // + + internal int Syntax_LastIndex() + { + // + Console.WriteLine($"The last word is {words[^1]}"); + // + return 0; + } + + internal int Syntax_Range() + { + // + string[] quickBrownFox = words[1..4]; + foreach (var word in quickBrownFox) + Console.Write($"< {word} >"); + Console.WriteLine(); + // + return 0; + } + + internal int Syntax_LastRange() + { + // + string[] lazyDog = words[^2..^0]; + foreach (var word in lazyDog) + Console.Write($"< {word} >"); + Console.WriteLine(); + // + return 0; + } + + internal int Syntax_PartialRange() + { + // + string[] allWords = words[..]; // contains "The" through "dog". + string[] firstPhrase = words[..4]; // contains "The" through "fox" + string[] lastPhrase = words[6..]; // contains "the", "lazy" and "dog" + foreach (var word in allWords) + Console.Write($"< {word} >"); + Console.WriteLine(); + foreach (var word in firstPhrase) + Console.Write($"< {word} >"); + Console.WriteLine(); + foreach (var word in lastPhrase) + Console.Write($"< {word} >"); + Console.WriteLine(); + // + return 0; + } + + internal int Syntax_IndexRangeType() + { + // + Index the = ^3; + Console.WriteLine(words[the]); + Range phrase = 1..4; + string[] text = words[phrase]; + foreach (var word in text) + Console.Write($"< {word} >"); + Console.WriteLine(); + // + return 0; + } + + internal int Syntax_WhyChosenSemantics() + { + // + int[] numbers = Enumerable.Range(0, 100).ToArray(); + int x = 12; + int y = 25; + int z = 36; + + Console.WriteLine($"{numbers[^x]} is the same as {numbers[numbers.Length - x]}"); + Console.WriteLine($"{numbers[x..y].Length} is the same as {y - x}"); + + Console.WriteLine("numbers[x..y] and numbers[y..z] are consecutive and disjoint:"); + Span x_y = numbers[x..y]; + Span y_z = numbers[y..z]; + Console.WriteLine($"\tnumbers[x..y] is {x_y[0]} through {x_y[^1]}, numbers[y..z] is {y_z[0]} through {y_z[^1]}"); + + Console.WriteLine("numbers[x..^x] removes x elements at each end:"); + Span x_x = numbers[x..^x]; + Console.WriteLine($"\tnumbers[x..^x] starts with {x_x[0]} and ends with {x_x[^1]}"); + + Console.WriteLine("numbers[..x] means numbers[0..x] and numbers[x..] means numbers[x..^0]"); + Span start_x = numbers[..x]; + Span zero_x = numbers[0..x]; + Console.WriteLine($"\t{start_x[0]}..{start_x[^1]} is the same as {zero_x[0]}..{zero_x[^1]}"); + Span z_end = numbers[z..]; + Span z_zero = numbers[z..^0]; + Console.WriteLine($"\t{z_end[0]}..{z_end[^1]} is the same as {z_zero[0]}..{z_zero[^1]}"); + // + return 0; + } + + internal int ComputeMovingAverages() + { + // + int[] sequence = Sequence(1000); + + for(int start = 0; start < sequence.Length; start += 100) + { + Range r = start..(start+10); + var (min, max, average) = MovingAverage(sequence, r); + Console.WriteLine($"From {r.Start} to {r.End}: \tMin: {min},\tMax: {max},\tAverage: {average}"); + } + + for (int start = 0; start < sequence.Length; start += 100) + { + Range r = ^(start + 10)..^start; + var (min, max, average) = MovingAverage(sequence, r); + Console.WriteLine($"From {r.Start} to {r.End}: \tMin: {min},\tMax: {max},\tAverage: {average}"); + } + + (int min, int max, double average) MovingAverage(int[] subSequence, Range range) => + ( + subSequence[range].Min(), + subSequence[range].Max(), + subSequence[range].Average() + ); + + int[] Sequence(int count) => + Enumerable.Range(0, count).Select(x => (int)(Math.Sqrt(x) * 100)).ToArray(); + // + + return 0; + } + + internal int JaggedArrays() + { + // + var jagged = new int[10][] + { + new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, + new int[10] { 10,11,12,13,14,15,16,17,18,19 }, + new int[10] { 20,21,22,23,24,25,26,27,28,29 }, + new int[10] { 30,31,32,33,34,35,36,37,38,39 }, + new int[10] { 40,41,42,43,44,45,46,47,48,49 }, + new int[10] { 50,51,52,53,54,55,56,57,58,59 }, + new int[10] { 60,61,62,63,64,65,66,67,68,69 }, + new int[10] { 70,71,72,73,74,75,76,77,78,79 }, + new int[10] { 80,81,82,83,84,85,86,87,88,89 }, + new int[10] { 90,91,92,93,94,95,96,97,98,99 }, + }; + + var selectedRows = jagged[3..^3]; + + foreach (var row in selectedRows) + { + var selectedColumns = row[2..^2]; + foreach (var cell in selectedColumns) + { + Console.Write($"{cell}, "); + } + Console.WriteLine(); + } + // + return 0; + } + + internal void ImplicitRangeOperatorConversion() + { + // + Range implicitRange = 3..^5; + + Range explicitRange = new( + start: new Index(value: 3, fromEnd: false), + end: new Index(value: 5, fromEnd: true)); + + if (implicitRange.Equals(explicitRange)) + { + Console.WriteLine( + $"The implicit range '{implicitRange}' equals the explicit range '{explicitRange}'"); + } + // Sample output: + // The implicit range '3..^5' equals the explicit range '3..^5' + // + } +} diff --git a/docs/csharp/tutorials/snippets/RangesIndexes/Program.cs b/docs/csharp/tutorials/snippets/RangesIndexes/Program.cs new file mode 100644 index 0000000000000..dc23de8d90c53 --- /dev/null +++ b/docs/csharp/tutorials/snippets/RangesIndexes/Program.cs @@ -0,0 +1,22 @@ +using RangesIndexes; + +Console.WriteLine("========== Starting Index and Range Samples. =========="); +var indexSamples = new IndicesAndRanges(); +Console.WriteLine(" ========== Last Index. =========="); +indexSamples.Syntax_LastIndex(); +Console.WriteLine(" ========== Range. =========="); +indexSamples.Syntax_Range(); +Console.WriteLine(" ========== Last Range. =========="); +indexSamples.Syntax_LastRange(); +Console.WriteLine(" ========== Partial Range. =========="); +indexSamples.Syntax_PartialRange(); +Console.WriteLine(" ========== Index and Range types. =========="); +indexSamples.Syntax_IndexRangeType(); +Console.WriteLine(" ========== Why this syntax. =========="); +indexSamples.Syntax_WhyChosenSemantics(); +Console.WriteLine(" ========== Scenario. =========="); +indexSamples.ComputeMovingAverages(); +Console.WriteLine(" ========== Jageged arrays. =========="); +indexSamples.JaggedArrays(); +Console.WriteLine(" ========== Implicit range operator expression conversions. =========="); +indexSamples.ImplicitRangeOperatorConversion(); diff --git a/docs/csharp/tutorials/snippets/RangesIndexes/RangesIndexes.csproj b/docs/csharp/tutorials/snippets/RangesIndexes/RangesIndexes.csproj new file mode 100644 index 0000000000000..59ed84ca9213d --- /dev/null +++ b/docs/csharp/tutorials/snippets/RangesIndexes/RangesIndexes.csproj @@ -0,0 +1,10 @@ + + + + Exe + net7.0 + enable + enable + + + diff --git a/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/ICustomer.cs b/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/ICustomer.cs new file mode 100644 index 0000000000000..4f02e70810deb --- /dev/null +++ b/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/ICustomer.cs @@ -0,0 +1,80 @@ +namespace customer_relationship; + +public interface ICustomer +{ + IEnumerable PreviousOrders { get; } + + DateTime DateJoined { get; } + DateTime? LastOrder { get; } + string Name { get; } + IDictionary Reminders { get; } + + /* + // + // Version 1: + public decimal ComputeLoyaltyDiscount() + { + DateTime TwoYearsAgo = DateTime.Now.AddYears(-2); + if ((DateJoined < TwoYearsAgo) && (PreviousOrders.Count() > 10)) + { + return 0.10m; + } + return 0; + } + // + */ + + /* + // + // Version 2: + public static void SetLoyaltyThresholds( + TimeSpan ago, + int minimumOrders = 10, + decimal percentageDiscount = 0.10m) + { + length = ago; + orderCount = minimumOrders; + discountPercent = percentageDiscount; + } + private static TimeSpan length = new TimeSpan(365 * 2, 0,0,0); // two years + private static int orderCount = 10; + private static decimal discountPercent = 0.10m; + + public decimal ComputeLoyaltyDiscount() + { + DateTime start = DateTime.Now - length; + + if ((DateJoined < start) && (PreviousOrders.Count() > orderCount)) + { + return discountPercent; + } + return 0; + } + // + */ + + // Version 3: + public static void SetLoyaltyThresholds(TimeSpan ago, int minimumOrders, decimal percentageDiscount) + { + length = ago; + orderCount = minimumOrders; + discountPercent = percentageDiscount; + } + private static TimeSpan length = new TimeSpan(365 * 2, 0, 0, 0); // two years + private static int orderCount = 10; + private static decimal discountPercent = 0.10m; + + // + public decimal ComputeLoyaltyDiscount() => DefaultLoyaltyDiscount(this); + protected static decimal DefaultLoyaltyDiscount(ICustomer c) + { + DateTime start = DateTime.Now - length; + + if ((c.DateJoined < start) && (c.PreviousOrders.Count() > orderCount)) + { + return discountPercent; + } + return 0; + } + // +} diff --git a/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/IOrder.cs b/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/IOrder.cs new file mode 100644 index 0000000000000..0f88122ab856c --- /dev/null +++ b/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/IOrder.cs @@ -0,0 +1,7 @@ +namespace customer_relationship; + +public interface IOrder +{ + DateTime Purchased { get; } + decimal Cost { get; } +} diff --git a/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/Program.cs b/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/Program.cs new file mode 100644 index 0000000000000..8311fa0e82979 --- /dev/null +++ b/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/Program.cs @@ -0,0 +1,50 @@ +using customer_relationship; +// +SampleCustomer c = new SampleCustomer("customer one", new DateTime(2010, 5, 31)) +{ + Reminders = + { + { new DateTime(2010, 08, 12), "childs's birthday" }, + { new DateTime(1012, 11, 15), "anniversary" } + } +}; + +SampleOrder o = new SampleOrder(new DateTime(2012, 6, 1), 5m); +c.AddOrder(o); + +o = new SampleOrder(new DateTime(2103, 7, 4), 25m); +c.AddOrder(o); + +// +// Check the discount: +ICustomer theCustomer = c; +Console.WriteLine($"Current discount: {theCustomer.ComputeLoyaltyDiscount()}"); +// +// + +// Add more orders to get the discount: +DateTime recurring = new DateTime(2013, 3, 15); +for(int i = 0; i < 15; i++) +{ + o = new SampleOrder(recurring, 19.23m * i); + c.AddOrder(o); + + recurring.AddMonths(2); +} + +Console.WriteLine($"Data about {c.Name}"); +Console.WriteLine($"Joined on {c.DateJoined}. Made {c.PreviousOrders.Count()} orders, the last on {c.LastOrder}"); +Console.WriteLine("Reminders:"); +foreach(var item in c.Reminders) +{ + Console.WriteLine($"\t{item.Value} on {item.Key}"); +} +foreach (IOrder order in c.PreviousOrders) + Console.WriteLine($"Order on {order.Purchased} for {order.Cost}"); + +Console.WriteLine($"Current discount: {theCustomer.ComputeLoyaltyDiscount()}"); + +// +ICustomer.SetLoyaltyThresholds(new TimeSpan(30, 0, 0, 0), 1, 0.25m); +Console.WriteLine($"Current discount: {theCustomer.ComputeLoyaltyDiscount()}"); +// diff --git a/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/SampleCustomer.cs b/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/SampleCustomer.cs new file mode 100644 index 0000000000000..93092ce33dcaf --- /dev/null +++ b/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/SampleCustomer.cs @@ -0,0 +1,37 @@ +namespace customer_relationship; + +public class SampleCustomer : ICustomer +{ + public SampleCustomer(string name, DateTime dateJoined) => + (Name, DateJoined) = (name, dateJoined); + + private List allOrders = new List(); + + public IEnumerable PreviousOrders => allOrders; + + public DateTime DateJoined { get; } + + public DateTime? LastOrder { get; private set; } + + public string Name { get; } + + private Dictionary reminders = new Dictionary(); + public IDictionary Reminders => reminders; + + public void AddOrder(IOrder order) + { + if (order.Purchased > (LastOrder ?? DateTime.MinValue)) + LastOrder = order.Purchased; + allOrders.Add(order); + } + + // + public decimal ComputeLoyaltyDiscount() + { + if (PreviousOrders.Any() == false) + return 0.50m; + else + return ICustomer.DefaultLoyaltyDiscount(this); + } + // +} diff --git a/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/SampleOrder.cs b/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/SampleOrder.cs new file mode 100644 index 0000000000000..89ba7bda0406a --- /dev/null +++ b/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/SampleOrder.cs @@ -0,0 +1,11 @@ +namespace customer_relationship; + +public class SampleOrder : IOrder +{ + public SampleOrder(DateTime purchase, decimal cost) => + (Purchased, Cost) = (purchase, cost); + + public DateTime Purchased { get; } + + public decimal Cost { get; } +} diff --git a/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/customer-relationship.csproj b/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/customer-relationship.csproj new file mode 100644 index 0000000000000..af50914e7f147 --- /dev/null +++ b/docs/csharp/tutorials/snippets/default-interface-members-versions/finished/customer-relationship/customer-relationship.csproj @@ -0,0 +1,11 @@ + + + + Exe + net7.0 + customer_relationship + enable + enable + + + diff --git a/docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/ICustomer.cs b/docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/ICustomer.cs new file mode 100644 index 0000000000000..4884330e26ebb --- /dev/null +++ b/docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/ICustomer.cs @@ -0,0 +1,13 @@ +namespace customer_relationship; + +// +public interface ICustomer +{ + IEnumerable PreviousOrders { get; } + + DateTime DateJoined { get; } + DateTime? LastOrder { get; } + string Name { get; } + IDictionary Reminders { get; } +} +// diff --git a/docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/IOrder.cs b/docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/IOrder.cs new file mode 100644 index 0000000000000..4ce317af31928 --- /dev/null +++ b/docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/IOrder.cs @@ -0,0 +1,9 @@ +namespace customer_relationship; + +// +public interface IOrder +{ + DateTime Purchased { get; } + decimal Cost { get; } +} +// diff --git a/docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/Program.cs b/docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/Program.cs new file mode 100644 index 0000000000000..f0b294dfba0eb --- /dev/null +++ b/docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/Program.cs @@ -0,0 +1,26 @@ +using customer_relationship; + +SampleCustomer c = new SampleCustomer("customer one", new DateTime(2010, 5, 31)) +{ + Reminders = + { + { new DateTime(2010, 08, 12), "childs's birthday" }, + { new DateTime(1012, 11, 15), "anniversary" } + } +}; + +SampleOrder o = new SampleOrder(new DateTime(2012, 6, 1), 5m); +c.AddOrder(o); + +o = new SampleOrder(new DateTime(2103, 7, 4), 25m); +c.AddOrder(o); + +Console.WriteLine($"Data about {c.Name}"); +Console.WriteLine($"Joined on {c.DateJoined}. Made {c.PreviousOrders.Count()} orders, the last on {c.LastOrder}"); +Console.WriteLine("Reminders:"); +foreach (var item in c.Reminders) +{ + Console.WriteLine($"\t{item.Value} on {item.Key}"); +} +foreach (IOrder order in c.PreviousOrders) + Console.WriteLine($"Order on {order.Purchased} for {order.Cost}"); diff --git a/docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/SampleCustomer.cs b/docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/SampleCustomer.cs new file mode 100644 index 0000000000000..35507b45f2610 --- /dev/null +++ b/docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/SampleCustomer.cs @@ -0,0 +1,27 @@ +namespace customer_relationship; + +public class SampleCustomer : ICustomer +{ + public SampleCustomer(string name, DateTime dateJoined) => + (Name, DateJoined) = (name, dateJoined); + + private List allOrders = new List(); + + public IEnumerable PreviousOrders => allOrders; + + public DateTime DateJoined { get; } + + public DateTime? LastOrder { get; private set; } + + public string Name { get; } + + private Dictionary reminders = new Dictionary(); + public IDictionary Reminders => reminders; + + public void AddOrder(IOrder order) + { + if (order.Purchased > (LastOrder ?? DateTime.MinValue)) + LastOrder = order.Purchased; + allOrders.Add(order); + } +} diff --git a/docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/SampleOrder.cs b/docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/SampleOrder.cs new file mode 100644 index 0000000000000..89ba7bda0406a --- /dev/null +++ b/docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/SampleOrder.cs @@ -0,0 +1,11 @@ +namespace customer_relationship; + +public class SampleOrder : IOrder +{ + public SampleOrder(DateTime purchase, decimal cost) => + (Purchased, Cost) = (purchase, cost); + + public DateTime Purchased { get; } + + public decimal Cost { get; } +} diff --git a/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/customer-relationship.csproj b/docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/customer-relationship.csproj similarity index 58% rename from samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/customer-relationship.csproj rename to docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/customer-relationship.csproj index 48a1d06fbcd80..45735a94afd06 100644 --- a/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/customer-relationship.csproj +++ b/docs/csharp/tutorials/snippets/default-interface-members-versions/starter/customer-relationship/customer-relationship.csproj @@ -2,8 +2,10 @@ Exe - net6.0 + net7.0 customer_relationship + enable + enable diff --git a/docs/csharp/whats-new/tutorials/snippets/generate-consume-asynchronous-streams/finished/IssuePRreport.csproj b/docs/csharp/tutorials/snippets/generate-consume-asynchronous-streams/finished/IssuePRreport.csproj similarity index 88% rename from docs/csharp/whats-new/tutorials/snippets/generate-consume-asynchronous-streams/finished/IssuePRreport.csproj rename to docs/csharp/tutorials/snippets/generate-consume-asynchronous-streams/finished/IssuePRreport.csproj index 418b82fee7dfa..792371ee415fa 100644 --- a/docs/csharp/whats-new/tutorials/snippets/generate-consume-asynchronous-streams/finished/IssuePRreport.csproj +++ b/docs/csharp/tutorials/snippets/generate-consume-asynchronous-streams/finished/IssuePRreport.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net7.0 enable enable diff --git a/docs/csharp/whats-new/tutorials/snippets/generate-consume-asynchronous-streams/finished/Program.cs b/docs/csharp/tutorials/snippets/generate-consume-asynchronous-streams/finished/Program.cs similarity index 100% rename from docs/csharp/whats-new/tutorials/snippets/generate-consume-asynchronous-streams/finished/Program.cs rename to docs/csharp/tutorials/snippets/generate-consume-asynchronous-streams/finished/Program.cs diff --git a/docs/csharp/whats-new/tutorials/snippets/generate-consume-asynchronous-streams/start/IssuePRreport.csproj b/docs/csharp/tutorials/snippets/generate-consume-asynchronous-streams/start/IssuePRreport.csproj similarity index 88% rename from docs/csharp/whats-new/tutorials/snippets/generate-consume-asynchronous-streams/start/IssuePRreport.csproj rename to docs/csharp/tutorials/snippets/generate-consume-asynchronous-streams/start/IssuePRreport.csproj index 418b82fee7dfa..792371ee415fa 100644 --- a/docs/csharp/whats-new/tutorials/snippets/generate-consume-asynchronous-streams/start/IssuePRreport.csproj +++ b/docs/csharp/tutorials/snippets/generate-consume-asynchronous-streams/start/IssuePRreport.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net7.0 enable enable diff --git a/docs/csharp/whats-new/tutorials/snippets/generate-consume-asynchronous-streams/start/Program.cs b/docs/csharp/tutorials/snippets/generate-consume-asynchronous-streams/start/Program.cs similarity index 100% rename from docs/csharp/whats-new/tutorials/snippets/generate-consume-asynchronous-streams/start/Program.cs rename to docs/csharp/tutorials/snippets/generate-consume-asynchronous-streams/start/Program.cs diff --git a/docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/ExtraFancyLight.cs b/docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/ExtraFancyLight.cs similarity index 100% rename from docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/ExtraFancyLight.cs rename to docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/ExtraFancyLight.cs diff --git a/docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/HalogenLight.cs b/docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/HalogenLight.cs similarity index 100% rename from docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/HalogenLight.cs rename to docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/HalogenLight.cs diff --git a/docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/IBlinkingLight.cs b/docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/IBlinkingLight.cs similarity index 100% rename from docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/IBlinkingLight.cs rename to docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/IBlinkingLight.cs diff --git a/docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/ILight.cs b/docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/ILight.cs similarity index 100% rename from docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/ILight.cs rename to docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/ILight.cs diff --git a/docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/ITimerLight.cs b/docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/ITimerLight.cs similarity index 100% rename from docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/ITimerLight.cs rename to docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/ITimerLight.cs diff --git a/docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/LEDLight.cs b/docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/LEDLight.cs similarity index 100% rename from docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/LEDLight.cs rename to docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/LEDLight.cs diff --git a/docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/OverheadLight.cs b/docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/OverheadLight.cs similarity index 100% rename from docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/OverheadLight.cs rename to docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/OverheadLight.cs diff --git a/docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/Program.cs b/docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/Program.cs similarity index 100% rename from docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/Program.cs rename to docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/Program.cs diff --git a/docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/UnusedExampleCode.cs b/docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/UnusedExampleCode.cs similarity index 100% rename from docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/UnusedExampleCode.cs rename to docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/UnusedExampleCode.cs diff --git a/docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/mixins-with-interfaces.csproj b/docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/mixins-with-interfaces.csproj similarity index 84% rename from docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/mixins-with-interfaces.csproj rename to docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/mixins-with-interfaces.csproj index cd1fd6f9b30a0..92a14e8f2f541 100644 --- a/docs/csharp/whats-new/tutorials/snippets/mixins-with-default-interface-methods/mixins-with-interfaces.csproj +++ b/docs/csharp/tutorials/snippets/mixins-with-default-interface-methods/mixins-with-interfaces.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net7.0 enable enable mixins_with_interfaces diff --git a/docs/csharp/whats-new/csharp-8.md b/docs/csharp/whats-new/csharp-8.md deleted file mode 100644 index 89a7114529bca..0000000000000 --- a/docs/csharp/whats-new/csharp-8.md +++ /dev/null @@ -1,531 +0,0 @@ ---- -title: What's new in C# 8.0 - C# Guide -description: Get an overview of the new features available in C# 8.0. -ms.date: 04/07/2020 ---- -# What's new in C# 8.0 - -C# 8.0 adds the following features and enhancements to the C# language: - -- [Readonly members](#readonly-members) -- [Default interface methods](#default-interface-methods) -- [Pattern matching enhancements](#more-patterns-in-more-places): - - [Switch expressions](#switch-expressions) - - [Property patterns](#property-patterns) - - [Tuple patterns](#tuple-patterns) - - [Positional patterns](#positional-patterns) -- [Using declarations](#using-declarations) -- [Static local functions](#static-local-functions) -- [Disposable ref structs](#disposable-ref-structs) -- [Nullable reference types](#nullable-reference-types) -- [Asynchronous streams](#asynchronous-streams) -- [Asynchronous disposable](#asynchronous-disposable) -- [Indices and ranges](#indices-and-ranges) -- [Null-coalescing assignment](#null-coalescing-assignment) -- [Unmanaged constructed types](#unmanaged-constructed-types) -- [Stackalloc in nested expressions](#stackalloc-in-nested-expressions) -- [Enhancement of interpolated verbatim strings](#enhancement-of-interpolated-verbatim-strings) - -C# 8.0 is supported on **.NET Core 3.x** and **.NET Standard 2.1**. For more information, see [C# language versioning](../language-reference/configure-language-version.md). - -The remainder of this article briefly describes these features. Where in-depth articles are available, links to those tutorials and overviews are provided. You can explore these features in your environment using the `dotnet try` global tool: - -1. Install the [dotnet-try](https://github.com/dotnet/try/blob/main/DotNetTryLocal.md) global tool. -1. Clone the [dotnet/try-samples](https://github.com/dotnet/try-samples) repository. -1. Set the current directory to the *csharp8* subdirectory for the *try-samples* repository. -1. Run `dotnet try`. - -## Readonly members - -You can apply the `readonly` modifier to members of a struct. It indicates that the member doesn't modify state. It's more granular than applying the `readonly` modifier to a `struct` declaration. Consider the following mutable struct: - -```csharp -public struct Point -{ - public double X { get; set; } - public double Y { get; set; } - public double Distance => Math.Sqrt(X * X + Y * Y); - - public override string ToString() => - $"({X}, {Y}) is {Distance} from the origin"; -} -``` - -Like most structs, the `ToString()` method doesn't modify state. You could indicate that by adding the `readonly` modifier to the declaration of `ToString()`: - -```csharp -public readonly override string ToString() => - $"({X}, {Y}) is {Distance} from the origin"; -``` - -The preceding change generates a compiler warning, because `ToString` accesses the `Distance` property, which isn't marked `readonly`: - -```console -warning CS8656: Call to non-readonly member 'Point.Distance.get' from a 'readonly' member results in an implicit copy of 'this' -``` - -The compiler warns you when it needs to create a defensive copy. The `Distance` property doesn't change state, so you can fix this warning by adding the `readonly` modifier to the declaration: - -```csharp -public readonly double Distance => Math.Sqrt(X * X + Y * Y); -``` - -Notice that the `readonly` modifier is necessary on a read-only property. The compiler doesn't assume `get` accessors don't modify state; you must declare `readonly` explicitly. Auto-implemented properties are an exception; the compiler will treat all auto-implemented getters as `readonly`, so here there's no need to add the `readonly` modifier to the `X` and `Y` properties. - -The compiler does enforce the rule that `readonly` members don't modify state. The following method won't compile unless you remove the `readonly` modifier: - -```csharp -public readonly void Translate(int xOffset, int yOffset) -{ - X += xOffset; - Y += yOffset; -} -``` - -This feature lets you specify your design intent so the compiler can enforce it, and make optimizations based on that intent. - -For more information, see the [`readonly` instance members](../language-reference/builtin-types/struct.md#readonly-instance-members) section of the [Structure types](../language-reference/builtin-types/struct.md) article. - -## Default interface methods - -You can now add members to interfaces and provide an implementation for those members. This language feature enables API authors to add methods to an interface in later versions without breaking source or binary compatibility with existing implementations of that interface. Existing implementations *inherit* the default implementation. This feature also enables C# to interoperate with APIs that target Android or Swift, which support similar features. Default interface methods also enable scenarios similar to a "traits" language feature. - -Default interface methods affect many scenarios and language elements. Our first tutorial covers [updating an interface with default implementations](./tutorials/default-interface-methods-versions.md). - -## More patterns in more places - -**Pattern matching** gives tools to provide shape-dependent functionality across related but different kinds of data. C# 7.0 introduced syntax for type patterns and constant patterns by using the [`is`](../language-reference/operators/is.md) expression and the [`switch`](../language-reference/statements/selection-statements.md#the-switch-statement) statement. These features represented the first tentative steps toward supporting programming paradigms where data and functionality live apart. As the industry moves toward more microservices and other cloud-based architectures, other language tools are needed. - -C# 8.0 expands this vocabulary so you can use more pattern expressions in more places in your code. Consider these features when your data and functionality are separate. Consider pattern matching when your algorithms depend on a fact other than the runtime type of an object. These techniques provide another way to express designs. - -In addition to new patterns in new places, C# 8.0 adds **recursive patterns**. Recursive patterns are patterns that can contain other patterns. - -### Switch expressions - -Often, a [`switch`](../language-reference/statements/selection-statements.md#the-switch-statement) statement produces a value in each of its `case` blocks. **Switch expressions** enable you to use more concise expression syntax. There are fewer repetitive `case` and `break` keywords, and fewer curly braces. As an example, consider the following enum that lists the colors of the rainbow: - -```csharp -public enum Rainbow -{ - Red, - Orange, - Yellow, - Green, - Blue, - Indigo, - Violet -} -``` - -If your application defined an `RGBColor` type that is constructed from the `R`, `G` and `B` components, you could convert a `Rainbow` value to its RGB values using the following method containing a switch expression: - -```csharp -public static RGBColor FromRainbow(Rainbow colorBand) => - colorBand switch - { - Rainbow.Red => new RGBColor(0xFF, 0x00, 0x00), - Rainbow.Orange => new RGBColor(0xFF, 0x7F, 0x00), - Rainbow.Yellow => new RGBColor(0xFF, 0xFF, 0x00), - Rainbow.Green => new RGBColor(0x00, 0xFF, 0x00), - Rainbow.Blue => new RGBColor(0x00, 0x00, 0xFF), - Rainbow.Indigo => new RGBColor(0x4B, 0x00, 0x82), - Rainbow.Violet => new RGBColor(0x94, 0x00, 0xD3), - _ => throw new ArgumentException(message: "invalid enum value", paramName: nameof(colorBand)), - }; -``` - -There are several syntax improvements here: - -- The variable comes before the `switch` keyword. The different order makes it visually easy to distinguish the switch expression from the switch statement. -- The `case` and `:` elements are replaced with `=>`. It's more concise and intuitive. -- The `default` case is replaced with a `_` discard. -- The bodies are expressions, not statements. - -Contrast that with the equivalent code using the classic `switch` statement: - -```csharp -public static RGBColor FromRainbowClassic(Rainbow colorBand) -{ - switch (colorBand) - { - case Rainbow.Red: - return new RGBColor(0xFF, 0x00, 0x00); - case Rainbow.Orange: - return new RGBColor(0xFF, 0x7F, 0x00); - case Rainbow.Yellow: - return new RGBColor(0xFF, 0xFF, 0x00); - case Rainbow.Green: - return new RGBColor(0x00, 0xFF, 0x00); - case Rainbow.Blue: - return new RGBColor(0x00, 0x00, 0xFF); - case Rainbow.Indigo: - return new RGBColor(0x4B, 0x00, 0x82); - case Rainbow.Violet: - return new RGBColor(0x94, 0x00, 0xD3); - default: - throw new ArgumentException(message: "invalid enum value", paramName: nameof(colorBand)); - }; -} -``` - -For more information, see [`switch` expression](../language-reference/operators/switch-expression.md). - -### Property patterns - -The **property pattern** enables you to match on properties of the object examined. Consider an eCommerce site that must compute sales tax based on the buyer's address. That computation isn't a core responsibility of an `Address` class. It will change over time, likely more often than address format changes. The amount of sales tax depends on the `State` property of the address. The following method uses the property pattern to compute the sales tax from the address and the price: - -```csharp -public static decimal ComputeSalesTax(Address location, decimal salePrice) => - location switch - { - { State: "WA" } => salePrice * 0.06M, - { State: "MN" } => salePrice * 0.075M, - { State: "MI" } => salePrice * 0.05M, - // other cases removed for brevity... - _ => 0M - }; -``` - -Pattern matching creates a concise syntax for expressing this algorithm. - -For more information, see the [Property pattern](../language-reference/operators/patterns.md#property-pattern) section of the [Patterns](../language-reference/operators/patterns.md) article. - -### Tuple patterns - -Some algorithms depend on multiple inputs. **Tuple patterns** allow you to switch based on multiple values expressed as a [tuple](../language-reference/builtin-types/value-tuples.md). The following code shows a switch expression for the game *rock, paper, scissors*: - -```csharp -public static string RockPaperScissors(string first, string second) - => (first, second) switch - { - ("rock", "paper") => "rock is covered by paper. Paper wins.", - ("rock", "scissors") => "rock breaks scissors. Rock wins.", - ("paper", "rock") => "paper covers rock. Paper wins.", - ("paper", "scissors") => "paper is cut by scissors. Scissors wins.", - ("scissors", "rock") => "scissors is broken by rock. Rock wins.", - ("scissors", "paper") => "scissors cuts paper. Scissors wins.", - (_, _) => "tie" - }; -``` - -The messages indicate the winner. The discard case represents the three combinations for ties, or other text inputs. - -### Positional patterns - -Some types include a `Deconstruct` method that deconstructs its properties into discrete variables. When a `Deconstruct` method is accessible, you can use **positional patterns** to inspect properties of the object and use those properties for a pattern. Consider the following `Point` class that includes a `Deconstruct` method to create discrete variables for `X` and `Y`: - -```csharp -public class Point -{ - public int X { get; } - public int Y { get; } - - public Point(int x, int y) => (X, Y) = (x, y); - - public void Deconstruct(out int x, out int y) => - (x, y) = (X, Y); -} -``` - -Additionally, consider the following enum that represents various positions of a quadrant: - -```csharp -public enum Quadrant -{ - Unknown, - Origin, - One, - Two, - Three, - Four, - OnBorder -} -``` - -The following method uses the **positional pattern** to extract the values of `x` and `y`. Then, it uses a `when` clause to determine the `Quadrant` of the point: - -```csharp -static Quadrant GetQuadrant(Point point) => point switch -{ - (0, 0) => Quadrant.Origin, - var (x, y) when x > 0 && y > 0 => Quadrant.One, - var (x, y) when x < 0 && y > 0 => Quadrant.Two, - var (x, y) when x < 0 && y < 0 => Quadrant.Three, - var (x, y) when x > 0 && y < 0 => Quadrant.Four, - var (_, _) => Quadrant.OnBorder, - _ => Quadrant.Unknown -}; -``` - -The discard pattern in the preceding switch matches when either `x` or `y` is 0, but not both. A switch expression must either produce a value or throw an exception. If none of the cases match, the switch expression throws an exception. The compiler generates a warning for you if you don't cover all possible cases in your switch expression. - -You can explore pattern matching techniques in this [advanced tutorial on pattern matching](../fundamentals/tutorials/pattern-matching.md). For more information about a positional pattern, see the [Positional pattern](../language-reference/operators/patterns.md#positional-pattern) section of the [Patterns](../language-reference/operators/patterns.md) article. - -## Using declarations - -A **using declaration** is a variable declaration preceded by the `using` keyword. It tells the compiler that the variable being declared should be disposed at the end of the enclosing scope. For example, consider the following code that writes a text file: - -```csharp -static int WriteLinesToFile(IEnumerable lines) -{ - using var file = new System.IO.StreamWriter("WriteLines2.txt"); - int skippedLines = 0; - foreach (string line in lines) - { - if (!line.Contains("Second")) - { - file.WriteLine(line); - } - else - { - skippedLines++; - } - } - // Notice how skippedLines is in scope here. - return skippedLines; - // file is disposed here -} -``` - -In the preceding example, the file is disposed when the closing brace for the method is reached. That's the end of the scope in which `file` is declared. The preceding code is equivalent to the following code that uses the classic [using statement](../language-reference/keywords/using-statement.md): - -```csharp -static int WriteLinesToFile(IEnumerable lines) -{ - using (var file = new System.IO.StreamWriter("WriteLines2.txt")) - { - int skippedLines = 0; - foreach (string line in lines) - { - if (!line.Contains("Second")) - { - file.WriteLine(line); - } - else - { - skippedLines++; - } - } - return skippedLines; - } // file is disposed here -} -``` - -In the preceding example, the file is disposed when the closing brace associated with the `using` statement is reached. - -In both cases, the compiler generates the call to `Dispose()`. The compiler generates an error if the expression in the `using` statement isn't disposable. - -## Static local functions - -You can now add the `static` modifier to [local functions](../programming-guide/classes-and-structs/local-functions.md) to ensure that local function doesn't capture (reference) any variables from the enclosing scope. Doing so generates `CS8421`, "A static local function can't contain a reference to \." - -Consider the following code. The local function `LocalFunction` accesses the variable `y`, declared in the enclosing scope (the method `M`). Therefore, `LocalFunction` can't be declared with the `static` modifier: - -```csharp -int M() -{ - int y; - LocalFunction(); - return y; - - void LocalFunction() => y = 0; -} -``` - -The following code contains a static local function. It can be static because it doesn't access any variables in the enclosing scope: - -```csharp -int M() -{ - int y = 5; - int x = 7; - return Add(x, y); - - static int Add(int left, int right) => left + right; -} -``` - -## Disposable ref structs - -A `struct` declared with the `ref` modifier may not implement any interfaces and so can't implement . Therefore, to enable a `ref struct` to be disposed, it must have an accessible `void Dispose()` method. This feature also applies to `readonly ref struct` declarations. - -## Nullable reference types - -Inside a nullable annotation context, any variable of a reference type is considered to be a **nonnullable reference type**. If you want to indicate that a variable may be null, you must append the type name with the `?` to declare the variable as a **nullable reference type**. - -For nonnullable reference types, the compiler uses flow analysis to ensure that local variables are initialized to a non-null value when declared. Fields must be initialized during construction. The compiler generates a warning if the variable isn't set by a call to any of the available constructors or by an initializer. Furthermore, nonnullable reference types can't be assigned a value that could be null. - -Nullable reference types aren't checked to ensure they aren't assigned or initialized to null. However, the compiler uses flow analysis to ensure that any variable of a nullable reference type is checked against null before it's accessed or assigned to a nonnullable reference type. - -You can learn more about the feature in the overview of [nullable reference types](../nullable-references.md). Try it yourself in a new application in this [nullable reference types tutorial](tutorials/nullable-reference-types.md). Learn about the steps to migrate an existing codebase to make use of nullable reference types in the article on [upgrading to nullable reference types](../nullable-migration-strategies.md). - -## Asynchronous streams - -Starting with C# 8.0, you can create and consume streams asynchronously. A method that returns an asynchronous stream has three properties: - -1. It's declared with the `async` modifier. -1. It returns an . -1. The method contains `yield return` statements to return successive elements in the asynchronous stream. - -Consuming an asynchronous stream requires you to add the `await` keyword before the `foreach` keyword when you enumerate the elements of the stream. Adding the `await` keyword requires the method that enumerates the asynchronous stream to be declared with the `async` modifier and to return a type allowed for an `async` method. Typically that means returning a or . It can also be a or . A method can both consume and produce an asynchronous stream, which means it would return an . The following code generates a sequence from 0 to 19, waiting 100 ms between generating each number: - -```csharp -public static async System.Collections.Generic.IAsyncEnumerable GenerateSequence() -{ - for (int i = 0; i < 20; i++) - { - await Task.Delay(100); - yield return i; - } -} -``` - -You would enumerate the sequence using the `await foreach` statement: - -```csharp -await foreach (var number in GenerateSequence()) -{ - Console.WriteLine(number); -} -``` - -You can try asynchronous streams yourself in our tutorial on [creating and consuming async streams](tutorials/generate-consume-asynchronous-stream.md). By default, stream elements are processed in the captured context. If you want to disable capturing of the context, use the extension method. For more information about synchronization contexts and capturing the current context, see the article on [consuming the Task-based asynchronous pattern](../../standard/asynchronous-programming-patterns/consuming-the-task-based-asynchronous-pattern.md). - -## Asynchronous disposable - -Starting with C# 8.0, the language supports asynchronous disposable types that implement the interface. You use the `await using` statement to work with an asynchronously disposable object. For more information, see the [Implement a DisposeAsync method](../../standard/garbage-collection/implementing-disposeasync.md) article. - -## Indices and ranges - -Indices and ranges provide a succinct syntax for accessing single elements or ranges in a sequence. - -This language support relies on two new types, and two new operators: - -- represents an index into a sequence. -- The index from end operator `^`, which specifies that an index is relative to the end of the sequence. -- represents a sub range of a sequence. -- The range operator `..`, which specifies the start and end of a range as its operands. - -Let's start with the rules for indexes. Consider an array `sequence`. The `0` index is the same as `sequence[0]`. The `^0` index is the same as `sequence[sequence.Length]`. Note that `sequence[^0]` does throw an exception, just as `sequence[sequence.Length]` does. For any number `n`, the index `^n` is the same as `sequence.Length - n`. - -A range specifies the *start* and *end* of a range. The start of the range is inclusive, but the end of the range is exclusive, meaning the *start* is included in the range but the *end* isn't included in the range. The range `[0..^0]` represents the entire range, just as `[0..sequence.Length]` represents the entire range. - -Let's look at a few examples. Consider the following array, annotated with its index from the start and from the end: - -```csharp -var words = new string[] -{ - // index from start index from end - "The", // 0 ^9 - "quick", // 1 ^8 - "brown", // 2 ^7 - "fox", // 3 ^6 - "jumped", // 4 ^5 - "over", // 5 ^4 - "the", // 6 ^3 - "lazy", // 7 ^2 - "dog" // 8 ^1 -}; // 9 (or words.Length) ^0 -``` - -You can retrieve the last word with the `^1` index: - -```csharp -Console.WriteLine($"The last word is {words[^1]}"); -// writes "dog" -``` - -The following code creates a subrange with the words "quick", "brown", and "fox". It includes `words[1]` through `words[3]`. The element `words[4]` isn't in the range. - -```csharp -var quickBrownFox = words[1..4]; -``` - -The following code creates a subrange with "lazy" and "dog". It includes `words[^2]` and `words[^1]`. The end index `words[^0]` isn't included: - -```csharp -var lazyDog = words[^2..^0]; -``` - -The following examples create ranges that are open ended for the start, end, or both: - -```csharp -var allWords = words[..]; // contains "The" through "dog". -var firstPhrase = words[..4]; // contains "The" through "fox" -var lastPhrase = words[6..]; // contains "the", "lazy" and "dog" -``` - -You can also declare ranges as variables: - -```csharp -Range phrase = 1..4; -``` - -The range can then be used inside the `[` and `]` characters: - -```csharp -var text = words[phrase]; -``` - -Not only arrays support indices and ranges. You can also use indices and ranges with [string](../language-reference/builtin-types/reference-types.md#the-string-type), , or . For more information, see [Type support for indices and ranges](tutorials/ranges-indexes.md#type-support-for-indices-and-ranges). - -You can explore more about indices and ranges in the tutorial on [indices and ranges](tutorials/ranges-indexes.md). - -## Null-coalescing assignment - -C# 8.0 introduces the null-coalescing assignment operator `??=`. You can use the `??=` operator to assign the value of its right-hand operand to its left-hand operand only if the left-hand operand evaluates to `null`. - -```csharp -List numbers = null; -int? i = null; - -numbers ??= new List(); -numbers.Add(i ??= 17); -numbers.Add(i ??= 20); - -Console.WriteLine(string.Join(" ", numbers)); // output: 17 17 -Console.WriteLine(i); // output: 17 -``` - -For more information, see the [?? and ??= operators](../language-reference/operators/null-coalescing-operator.md) article. - -## Unmanaged constructed types - -In C# 7.3 and earlier, a constructed type (a type that includes at least one type argument) can't be an [unmanaged type](../language-reference/builtin-types/unmanaged-types.md). Starting with C# 8.0, a constructed value type is unmanaged if it contains fields of unmanaged types only. - -For example, given the following definition of the generic `Coords` type: - -```csharp -public struct Coords -{ - public T X; - public T Y; -} -``` - -the `Coords` type is an unmanaged type in C# 8.0 and later. Like for any unmanaged type, you can create a pointer to a variable of this type or [allocate a block of memory on the stack](../language-reference/operators/stackalloc.md) for instances of this type: - -```csharp -Span> coordinates = stackalloc[] -{ - new Coords { X = 0, Y = 0 }, - new Coords { X = 0, Y = 3 }, - new Coords { X = 4, Y = 0 } -}; -``` - -For more information, see [Unmanaged types](../language-reference/builtin-types/unmanaged-types.md). - -## Stackalloc in nested expressions - -Starting with C# 8.0, if the result of a [stackalloc](../language-reference/operators/stackalloc.md) expression is of the or type, you can use the `stackalloc` expression in other expressions: - -```csharp -Span numbers = stackalloc[] { 1, 2, 3, 4, 5, 6 }; -var ind = numbers.IndexOfAny(stackalloc[] { 2, 4, 6, 8 }); -Console.WriteLine(ind); // output: 1 -``` - -## Enhancement of interpolated verbatim strings - -Order of the `$` and `@` tokens in [interpolated](../language-reference/tokens/interpolated.md) verbatim strings can be any: both `$@"..."` and `@$"..."` are valid interpolated verbatim strings. In earlier C# versions, the `$` token must appear before the `@` token. diff --git a/docs/csharp/whats-new/csharp-version-history.md b/docs/csharp/whats-new/csharp-version-history.md index 97ef49c622ba0..efc8f4dab64db 100644 --- a/docs/csharp/whats-new/csharp-version-history.md +++ b/docs/csharp/whats-new/csharp-version-history.md @@ -230,23 +230,23 @@ The new compiler options are: C# 8.0 is the first major C# release that specifically targets .NET Core. Some features rely on new CLR capabilities, others on library types added only in .NET Core. C# 8.0 adds the following features and enhancements to the C# language: -- [Readonly members](./csharp-8.md#readonly-members) -- [Default interface methods](./csharp-8.md#default-interface-methods) -- [Pattern matching enhancements](./csharp-8.md#more-patterns-in-more-places): - - [Switch expressions](./csharp-8.md#switch-expressions) - - [Property patterns](./csharp-8.md#property-patterns) - - [Tuple patterns](./csharp-8.md#tuple-patterns) - - [Positional patterns](./csharp-8.md#positional-patterns) -- [Using declarations](./csharp-8.md#using-declarations) -- [Static local functions](./csharp-8.md#static-local-functions) -- [Disposable ref structs](./csharp-8.md#disposable-ref-structs) +- [Readonly members](../language-reference/builtin-types/struct.md#readonly-instance-members) +- [Default interface methods](../language-reference/keywords/interface.md#default-interface-members) +- [Pattern matching enhancements](../language-reference/operators/patterns.md): + - Switch expressions + - Property patterns + - Tuple patterns + - Positional patterns +- [Using declarations](../language-reference/keywords/using-directive.md) +- [Static local functions](../programming-guide/classes-and-structs/local-functions.md) +- [Disposable ref structs](../language-reference/builtin-types/ref-struct.md) - [Nullable reference types](../language-reference/builtin-types/nullable-reference-types.md) -- [Asynchronous streams](./csharp-8.md#asynchronous-streams) -- [Indices and ranges](./csharp-8.md#indices-and-ranges) -- [Null-coalescing assignment](./csharp-8.md#null-coalescing-assignment) -- [Unmanaged constructed types](./csharp-8.md#unmanaged-constructed-types) -- [Stackalloc in nested expressions](./csharp-8.md#stackalloc-in-nested-expressions) -- [Enhancement of interpolated verbatim strings](./csharp-8.md#enhancement-of-interpolated-verbatim-strings) +- [Asynchronous streams](../language-reference/statements/iteration-statements.md#await-foreach) +- [Indices and ranges](../language-reference/operators/member-access-operators.md#range-operator-) +- [Null-coalescing assignment](../language-reference/operators/assignment-operator.md#null-coalescing-assignment) +- [Unmanaged constructed types](../language-reference/keywords/where-generic-type-constraint.md) +- [Stackalloc in nested expressions](../language-reference/operators/stackalloc.md) +- [Enhancement of interpolated verbatim strings](../language-reference/tokens/interpolated.md) Default interface members require enhancements in the CLR. Those features were added in the CLR for .NET Core 3.0. Ranges and indexes, and asynchronous streams require new types in the .NET Core 3.0 libraries. Nullable reference types, while implemented in the compiler, is much more useful when libraries are annotated to provide semantic information regarding the null state of arguments and return values. Those annotations are being added in the .NET Core libraries. diff --git a/docs/fsharp/whats-new/fsharp-50.md b/docs/fsharp/whats-new/fsharp-50.md index 17683e2d7e46b..bc8f96c93d739 100644 --- a/docs/fsharp/whats-new/fsharp-50.md +++ b/docs/fsharp/whats-new/fsharp-50.md @@ -362,7 +362,7 @@ This feature implements [F# RFC FS-1031](https://github.com/fsharp/fslang-design ## Default interface member consumption -F# 5 lets you consume [interfaces with default implementations](../../csharp/whats-new/tutorials/default-interface-methods-versions.md). +F# 5 lets you consume [interfaces with default implementations](../../csharp/tutorials/default-interface-methods-versions.md). Consider an interface defined in C# like this: diff --git a/docs/fsharp/whats-new/fsharp-6.md b/docs/fsharp/whats-new/fsharp-6.md index 5c3273ed01dcb..8ce854d7d0c1b 100644 --- a/docs/fsharp/whats-new/fsharp-6.md +++ b/docs/fsharp/whats-new/fsharp-6.md @@ -86,7 +86,7 @@ This feature implements [F# RFC FS-1039](https://github.com/fsharp/fslang-design ## Overloaded custom operations in computation expressions -F# 6 lets you consume [interfaces with default implementations](../../csharp/whats-new/tutorials/default-interface-methods-versions.md). +F# 6 lets you consume [interfaces with default implementations](../../csharp/tutorials/default-interface-methods-versions.md). Consider the following use of a computation expression builder `content`: diff --git a/docs/iot/tutorials/adc.md b/docs/iot/tutorials/adc.md index c460ce73b3bf7..e275f06ed1729 100644 --- a/docs/iot/tutorials/adc.md +++ b/docs/iot/tutorials/adc.md @@ -75,7 +75,7 @@ Complete the following steps in your preferred development environment: In the preceding code: - `hardwareSpiSettings` is set to a new instance of `SpiConnectionSettings`. The constructor sets the `busId` parameter to 0 and the `chipSelectLine` parameter to 0. - - A [using declaration](../../csharp/whats-new/csharp-8.md#using-declarations) creates an instance of `SpiDevice` by calling `SpiDevice.Create` and passing in `hardwareSpiSettings`. This `SpiDevice` represents the SPI bus. The `using` declaration ensures the object is disposed and hardware resources are released properly. + - A [using declaration](../../csharp/language-reference/keywords/using-statement.md) creates an instance of `SpiDevice` by calling `SpiDevice.Create` and passing in `hardwareSpiSettings`. This `SpiDevice` represents the SPI bus. The `using` declaration ensures the object is disposed and hardware resources are released properly. - Another `using` declaration creates an instance of `Mcp3008` and passes the `SpiDevice` into the constructor. - A `while` loop runs indefinitely. Each iteration: 1. Reads the value of CH0 on the ADC by calling `mcp.Read(0)`. diff --git a/docs/iot/tutorials/blink-led.md b/docs/iot/tutorials/blink-led.md index 18b5f16945a47..5c03a2b566f4a 100644 --- a/docs/iot/tutorials/blink-led.md +++ b/docs/iot/tutorials/blink-led.md @@ -59,7 +59,7 @@ Complete the following steps in your preferred development environment: In the preceding code: - - A [using declaration](../../csharp/whats-new/csharp-8.md#using-declarations) creates an instance of `GpioController`. The `using` declaration ensures the object is disposed and hardware resources are released properly. + - A [using declaration](../../csharp/language-reference/keywords/using-statement.md) creates an instance of `GpioController`. The `using` declaration ensures the object is disposed and hardware resources are released properly. - GPIO pin 18 is opened for output - A `while` loop runs indefinitely. Each iteration: 1. Writes a value to GPIO pin 18. If `ledOn` is true, it writes `PinValue.High` (on). Otherwise, it writes `PinValue.Low`. diff --git a/docs/iot/tutorials/lcd-display.md b/docs/iot/tutorials/lcd-display.md index 5c4a20f2312f6..f4758ebfa6918 100644 --- a/docs/iot/tutorials/lcd-display.md +++ b/docs/iot/tutorials/lcd-display.md @@ -67,7 +67,7 @@ Complete the following steps in your preferred development environment: In the preceding code: - - A [using declaration](../../csharp/whats-new/csharp-8.md#using-declarations) creates an instance of `I2cDevice` by calling `I2cDevice.Create` and passing in a new `I2cConnectionSettings` with the `busId` and `deviceAddress` parameters. This `I2cDevice` represents the I2C bus. The `using` declaration ensures the object is disposed and hardware resources are released properly. + - A [using declaration](../../csharp/language-reference/keywords/using-statement.md) creates an instance of `I2cDevice` by calling `I2cDevice.Create` and passing in a new `I2cConnectionSettings` with the `busId` and `deviceAddress` parameters. This `I2cDevice` represents the I2C bus. The `using` declaration ensures the object is disposed and hardware resources are released properly. > [!WARNING] > The device address for the GPIO expander depends on the chip used by the manufacturer. GPIO expanders equipped with a PCF8574 use the address `0x27`, while those using PCF8574A chips use `0x3F`. Consult your LCD's documentation. diff --git a/docs/iot/tutorials/temp-sensor.md b/docs/iot/tutorials/temp-sensor.md index a8fef28bdfb8a..2fe6f96f3dacf 100644 --- a/docs/iot/tutorials/temp-sensor.md +++ b/docs/iot/tutorials/temp-sensor.md @@ -73,7 +73,7 @@ Complete the following steps in your preferred development environment: > [!IMPORTANT] > Some BME280 breakout manufacturers use the secondary address value. For those devices, use `Bme280.SecondaryI2cAddress`. - - A [using declaration](../../csharp/whats-new/csharp-8.md#using-declarations) creates an instance of `I2cDevice` by calling `I2cDevice.Create` and passing in `i2cSettings`. This `I2cDevice` represents the I2C bus. The `using` declaration ensures the object is disposed and hardware resources are released properly. + - A [using declaration](../../csharp/language-reference/keywords/using-statement.md) creates an instance of `I2cDevice` by calling `I2cDevice.Create` and passing in `i2cSettings`. This `I2cDevice` represents the I2C bus. The `using` declaration ensures the object is disposed and hardware resources are released properly. - Another `using` declaration creates an instance of `Bme280` to represent the sensor. The `I2cDevice` is passed in the constructor. - The time required for the chip to take measurements with the chip's current (default) settings is retrieved by calling `GetMeasurementDuration`. - A `while` loop runs indefinitely. Each iteration: diff --git a/docs/standard/garbage-collection/implementing-disposeasync.md b/docs/standard/garbage-collection/implementing-disposeasync.md index b029b59e24026..874bcedc79e7c 100644 --- a/docs/standard/garbage-collection/implementing-disposeasync.md +++ b/docs/standard/garbage-collection/implementing-disposeasync.md @@ -117,7 +117,7 @@ For situations where the usage of `ConfigureAwait` is not needed, the `await usi :::code language="csharp" source="snippets/dispose-async/ExampleUsingStatementProgram.cs"::: -Furthermore, it could be written to use the implicit scoping of a [using declaration](../../csharp/whats-new/csharp-8.md#using-declarations). +Furthermore, it could be written to use the implicit scoping of a [using declaration](../../csharp/language-reference/keywords/using-statement.md). :::code language="csharp" source="snippets/dispose-async/ExampleUsingDeclarationProgram.cs"::: diff --git a/docs/standard/garbage-collection/using-objects.md b/docs/standard/garbage-collection/using-objects.md index 3077e80405fb0..524e81fdd9520 100644 --- a/docs/standard/garbage-collection/using-objects.md +++ b/docs/standard/garbage-collection/using-objects.md @@ -36,7 +36,7 @@ The following example uses the `using` statement to create and release a - var surveyRun = new SurveyRun(); - surveyRun.AddQuestion(QuestionType.YesNo, "Has your code ever thrown a NullReferenceException?"); - surveyRun.AddQuestion(new SurveyQuestion(QuestionType.Number, "How many times (to the nearest 100) has that happened?")); - surveyRun.AddQuestion(QuestionType.Text, "What is your favorite color?"); - // - - // - surveyRun.PerformSurvey(50); - // - - // - foreach (var participant in surveyRun.AllParticipants) - { - Console.WriteLine($"Participant: {participant.Id}:"); - if (participant.AnsweredSurvey) - { - for (int i = 0; i < surveyRun.Questions.Count; i++) - { - var answer = participant.Answer(i); - Console.WriteLine($"\t{surveyRun.GetQuestion(i).QuestionText} : {answer}"); - } - } - else - { - Console.WriteLine("\tNo responses"); - } - } - // - } - } -} diff --git a/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyQuestion.cs b/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyQuestion.cs deleted file mode 100644 index ca744f69a7693..0000000000000 --- a/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyQuestion.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace NullableIntroduction -{ - public enum QuestionType - { - YesNo, - Number, - Text - } - - public class SurveyQuestion - { - public string QuestionText { get; } - public QuestionType TypeOfQuestion { get; } - - public SurveyQuestion(QuestionType typeOfQuestion, string text) => - (TypeOfQuestion, QuestionText) = (typeOfQuestion, text); - } -} diff --git a/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyResponse.cs b/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyResponse.cs deleted file mode 100644 index 8279fce2134f7..0000000000000 --- a/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyResponse.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace NullableIntroduction -{ - public class SurveyResponse - { - // - private static readonly Random randomGenerator = new Random(); - public static SurveyResponse GetRandomId() => new SurveyResponse(randomGenerator.Next()); - // - - public int Id { get; } - - // - public bool AnsweredSurvey => surveyResponses != null; - public string Answer(int index) => surveyResponses?.GetValueOrDefault(index) ?? "No answer"; - // - - public SurveyResponse(int id) => Id = id; - - // - private Dictionary? surveyResponses; - public bool AnswerSurvey(IEnumerable questions) - { - if (ConsentToSurvey()) - { - surveyResponses = new Dictionary(); - int index = 0; - foreach (var question in questions) - { - var answer = GenerateAnswer(question); - if (answer != null) - { - surveyResponses.Add(index, answer); - } - index++; - } - } - return surveyResponses != null; - } - - private bool ConsentToSurvey() => randomGenerator.Next(0, 2) == 1; - - private string? GenerateAnswer(SurveyQuestion question) - { - switch (question.TypeOfQuestion) - { - case QuestionType.YesNo: - int n = randomGenerator.Next(-1, 2); - return (n == -1) ? default : (n == 0) ? "No" : "Yes"; - case QuestionType.Number: - n = randomGenerator.Next(-30, 101); - return (n < 0) ? default : n.ToString(); - case QuestionType.Text: - default: - switch (randomGenerator.Next(0, 5)) - { - case 0: - return default; - case 1: - return "Red"; - case 2: - return "Green"; - case 3: - return "Blue"; - } - return "Red. No, Green. Wait.. Blue... AAARGGGGGHHH!"; - } - } - // - } -} diff --git a/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyRun.cs b/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyRun.cs deleted file mode 100644 index 44da984e43593..0000000000000 --- a/samples/snippets/csharp/NullableIntroduction/NullableIntroduction/SurveyRun.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections.Generic; -using System.Linq; - -namespace NullableIntroduction -{ - public class SurveyRun - { - private List surveyQuestions = new List(); - - // - public IEnumerable AllParticipants => (respondents ?? Enumerable.Empty()); - public ICollection Questions => surveyQuestions; - public SurveyQuestion GetQuestion(int index) => surveyQuestions[index]; - // - - public void AddQuestion(QuestionType type, string question) => - AddQuestion(new SurveyQuestion(type, question)); - public void AddQuestion(SurveyQuestion surveyQuestion) => surveyQuestions.Add(surveyQuestion); - - // - private List? respondents; - public void PerformSurvey(int numberOfRespondents) - { - int respondentsConsenting = 0; - respondents = new List(); - while (respondentsConsenting < numberOfRespondents) - { - var respondent = SurveyResponse.GetRandomId(); - if (respondent.AnswerSurvey(surveyQuestions)) - respondentsConsenting++; - respondents.Add(respondent); - } - } - // - } -} diff --git a/samples/snippets/csharp/tutorials/RangesIndexes/IndicesAndRanges.cs b/samples/snippets/csharp/tutorials/RangesIndexes/IndicesAndRanges.cs deleted file mode 100644 index 6faf198505d35..0000000000000 --- a/samples/snippets/csharp/tutorials/RangesIndexes/IndicesAndRanges.cs +++ /dev/null @@ -1,202 +0,0 @@ -using System; -using System.Linq; - -namespace RangesIndexes -{ - class IndicesAndRanges - { - // - private string[] words = new string[] - { - // index from start index from end - "The", // 0 ^9 - "quick", // 1 ^8 - "brown", // 2 ^7 - "fox", // 3 ^6 - "jumped", // 4 ^5 - "over", // 5 ^4 - "the", // 6 ^3 - "lazy", // 7 ^2 - "dog" // 8 ^1 - }; - // - - internal int Syntax_LastIndex() - { - // - Console.WriteLine($"The last word is {words[^1]}"); - // - return 0; - } - - internal int Syntax_Range() - { - // - string[] quickBrownFox = words[1..4]; - foreach (var word in quickBrownFox) - Console.Write($"< {word} >"); - Console.WriteLine(); - // - return 0; - } - - internal int Syntax_LastRange() - { - // - string[] lazyDog = words[^2..^0]; - foreach (var word in lazyDog) - Console.Write($"< {word} >"); - Console.WriteLine(); - // - return 0; - } - - internal int Syntax_PartialRange() - { - // - string[] allWords = words[..]; // contains "The" through "dog". - string[] firstPhrase = words[..4]; // contains "The" through "fox" - string[] lastPhrase = words[6..]; // contains "the", "lazy" and "dog" - foreach (var word in allWords) - Console.Write($"< {word} >"); - Console.WriteLine(); - foreach (var word in firstPhrase) - Console.Write($"< {word} >"); - Console.WriteLine(); - foreach (var word in lastPhrase) - Console.Write($"< {word} >"); - Console.WriteLine(); - // - return 0; - } - - internal int Syntax_IndexRangeType() - { - // - Index the = ^3; - Console.WriteLine(words[the]); - Range phrase = 1..4; - string[] text = words[phrase]; - foreach (var word in text) - Console.Write($"< {word} >"); - Console.WriteLine(); - // - return 0; - } - - internal int Syntax_WhyChosenSemantics() - { - // - int[] numbers = Enumerable.Range(0, 100).ToArray(); - int x = 12; - int y = 25; - int z = 36; - - Console.WriteLine($"{numbers[^x]} is the same as {numbers[numbers.Length - x]}"); - Console.WriteLine($"{numbers[x..y].Length} is the same as {y - x}"); - - Console.WriteLine("numbers[x..y] and numbers[y..z] are consecutive and disjoint:"); - Span x_y = numbers[x..y]; - Span y_z = numbers[y..z]; - Console.WriteLine($"\tnumbers[x..y] is {x_y[0]} through {x_y[^1]}, numbers[y..z] is {y_z[0]} through {y_z[^1]}"); - - Console.WriteLine("numbers[x..^x] removes x elements at each end:"); - Span x_x = numbers[x..^x]; - Console.WriteLine($"\tnumbers[x..^x] starts with {x_x[0]} and ends with {x_x[^1]}"); - - Console.WriteLine("numbers[..x] means numbers[0..x] and numbers[x..] means numbers[x..^0]"); - Span start_x = numbers[..x]; - Span zero_x = numbers[0..x]; - Console.WriteLine($"\t{start_x[0]}..{start_x[^1]} is the same as {zero_x[0]}..{zero_x[^1]}"); - Span z_end = numbers[z..]; - Span z_zero = numbers[z..^0]; - Console.WriteLine($"\t{z_end[0]}..{z_end[^1]} is the same as {z_zero[0]}..{z_zero[^1]}"); - // - return 0; - } - - internal int ComputeMovingAverages() - { - // - int[] sequence = Sequence(1000); - - for(int start = 0; start < sequence.Length; start += 100) - { - Range r = start..(start+10); - var (min, max, average) = MovingAverage(sequence, r); - Console.WriteLine($"From {r.Start} to {r.End}: \tMin: {min},\tMax: {max},\tAverage: {average}"); - } - - for (int start = 0; start < sequence.Length; start += 100) - { - Range r = ^(start + 10)..^start; - var (min, max, average) = MovingAverage(sequence, r); - Console.WriteLine($"From {r.Start} to {r.End}: \tMin: {min},\tMax: {max},\tAverage: {average}"); - } - - (int min, int max, double average) MovingAverage(int[] subSequence, Range range) => - ( - subSequence[range].Min(), - subSequence[range].Max(), - subSequence[range].Average() - ); - - int[] Sequence(int count) => - Enumerable.Range(0, count).Select(x => (int)(Math.Sqrt(x) * 100)).ToArray(); - // - - return 0; - } - - internal int JaggedArrays() - { - // - var jagged = new int[10][] - { - new int[10] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, - new int[10] { 10,11,12,13,14,15,16,17,18,19 }, - new int[10] { 20,21,22,23,24,25,26,27,28,29 }, - new int[10] { 30,31,32,33,34,35,36,37,38,39 }, - new int[10] { 40,41,42,43,44,45,46,47,48,49 }, - new int[10] { 50,51,52,53,54,55,56,57,58,59 }, - new int[10] { 60,61,62,63,64,65,66,67,68,69 }, - new int[10] { 70,71,72,73,74,75,76,77,78,79 }, - new int[10] { 80,81,82,83,84,85,86,87,88,89 }, - new int[10] { 90,91,92,93,94,95,96,97,98,99 }, - }; - - var selectedRows = jagged[3..^3]; - - foreach (var row in selectedRows) - { - var selectedColumns = row[2..^2]; - foreach (var cell in selectedColumns) - { - Console.Write($"{cell}, "); - } - Console.WriteLine(); - } - // - return 0; - } - - internal void ImplicitRangeOperatorConversion() - { - // - Range implicitRange = 3..^5; - - Range explicitRange = new( - start: new Index(value: 3, fromEnd: false), - end: new Index(value: 5, fromEnd: true)); - - if (implicitRange.Equals(explicitRange)) - { - Console.WriteLine( - $"The implicit range '{implicitRange}' equals the explicit range '{explicitRange}'"); - } - // Sample output: - // The implicit range '3..^5' equals the explicit range '3..^5' - // - } - } -} diff --git a/samples/snippets/csharp/tutorials/RangesIndexes/Program.cs b/samples/snippets/csharp/tutorials/RangesIndexes/Program.cs deleted file mode 100644 index 7a9869fbfd849..0000000000000 --- a/samples/snippets/csharp/tutorials/RangesIndexes/Program.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; - -namespace RangesIndexes -{ - class Program - { - static void Main(string[] args) - { - Console.WriteLine("========== Starting Index and Range Samples. =========="); - var indexSamples = new IndicesAndRanges(); - Console.WriteLine(" ========== Last Index. =========="); - indexSamples.Syntax_LastIndex(); - Console.WriteLine(" ========== Range. =========="); - indexSamples.Syntax_Range(); - Console.WriteLine(" ========== Last Range. =========="); - indexSamples.Syntax_LastRange(); - Console.WriteLine(" ========== Partial Range. =========="); - indexSamples.Syntax_PartialRange(); - Console.WriteLine(" ========== Index and Range types. =========="); - indexSamples.Syntax_IndexRangeType(); - Console.WriteLine(" ========== Why this syntax. =========="); - indexSamples.Syntax_WhyChosenSemantics(); - Console.WriteLine(" ========== Scenario. =========="); - indexSamples.ComputeMovingAverages(); - Console.WriteLine(" ========== Jageged arrays. =========="); - indexSamples.JaggedArrays(); - Console.WriteLine(" ========== Implicit range operator expression conversions. =========="); - indexSamples.ImplicitRangeOperatorConversion(); - } - } -} diff --git a/samples/snippets/csharp/tutorials/RangesIndexes/RangesIndexes.csproj b/samples/snippets/csharp/tutorials/RangesIndexes/RangesIndexes.csproj deleted file mode 100644 index 41f1d5ad4b264..0000000000000 --- a/samples/snippets/csharp/tutorials/RangesIndexes/RangesIndexes.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - Exe - net6.0 - - - diff --git a/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/ICustomer.cs b/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/ICustomer.cs deleted file mode 100644 index acea0fa64c644..0000000000000 --- a/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/ICustomer.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace customer_relationship -{ - public interface ICustomer - { - IEnumerable PreviousOrders { get; } - - DateTime DateJoined { get; } - DateTime? LastOrder { get; } - string Name { get; } - IDictionary Reminders { get; } - - /* - // - // Version 1: - public decimal ComputeLoyaltyDiscount() - { - DateTime TwoYearsAgo = DateTime.Now.AddYears(-2); - if ((DateJoined < TwoYearsAgo) && (PreviousOrders.Count() > 10)) - { - return 0.10m; - } - return 0; - } - // - */ - - /* - // - // Version 2: - public static void SetLoyaltyThresholds( - TimeSpan ago, - int minimumOrders = 10, - decimal percentageDiscount = 0.10m) - { - length = ago; - orderCount = minimumOrders; - discountPercent = percentageDiscount; - } - private static TimeSpan length = new TimeSpan(365 * 2, 0,0,0); // two years - private static int orderCount = 10; - private static decimal discountPercent = 0.10m; - - public decimal ComputeLoyaltyDiscount() - { - DateTime start = DateTime.Now - length; - - if ((DateJoined < start) && (PreviousOrders.Count() > orderCount)) - { - return discountPercent; - } - return 0; - } - // - */ - - // Version 3: - public static void SetLoyaltyThresholds(TimeSpan ago, int minimumOrders, decimal percentageDiscount) - { - length = ago; - orderCount = minimumOrders; - discountPercent = percentageDiscount; - } - private static TimeSpan length = new TimeSpan(365 * 2, 0, 0, 0); // two years - private static int orderCount = 10; - private static decimal discountPercent = 0.10m; - - // - public decimal ComputeLoyaltyDiscount() => DefaultLoyaltyDiscount(this); - protected static decimal DefaultLoyaltyDiscount(ICustomer c) - { - DateTime start = DateTime.Now - length; - - if ((c.DateJoined < start) && (c.PreviousOrders.Count() > orderCount)) - { - return discountPercent; - } - return 0; - } - // - } -} diff --git a/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/IOrder.cs b/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/IOrder.cs deleted file mode 100644 index 507b3073d30bb..0000000000000 --- a/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/IOrder.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; - -namespace customer_relationship -{ - public interface IOrder - { - DateTime Purchased { get; } - decimal Cost { get; } - } -} diff --git a/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/Program.cs b/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/Program.cs deleted file mode 100644 index d11b3728c3db0..0000000000000 --- a/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/Program.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Linq; - -namespace customer_relationship -{ - class Program - { - static void Main(string[] args) - { - // - SampleCustomer c = new SampleCustomer("customer one", new DateTime(2010, 5, 31)) - { - Reminders = - { - { new DateTime(2010, 08, 12), "childs's birthday" }, - { new DateTime(1012, 11, 15), "anniversary" } - } - }; - - SampleOrder o = new SampleOrder(new DateTime(2012, 6, 1), 5m); - c.AddOrder(o); - - o = new SampleOrder(new DateTime(2103, 7, 4), 25m); - c.AddOrder(o); - - // - // Check the discount: - ICustomer theCustomer = c; - Console.WriteLine($"Current discount: {theCustomer.ComputeLoyaltyDiscount()}"); - // - // - - // Add more orders to get the discount: - DateTime recurring = new DateTime(2013, 3, 15); - for(int i = 0; i < 15; i++) - { - o = new SampleOrder(recurring, 19.23m * i); - c.AddOrder(o); - - recurring.AddMonths(2); - } - - Console.WriteLine($"Data about {c.Name}"); - Console.WriteLine($"Joined on {c.DateJoined}. Made {c.PreviousOrders.Count()} orders, the last on {c.LastOrder}"); - Console.WriteLine("Reminders:"); - foreach(var item in c.Reminders) - { - Console.WriteLine($"\t{item.Value} on {item.Key}"); - } - foreach (IOrder order in c.PreviousOrders) - Console.WriteLine($"Order on {order.Purchased} for {order.Cost}"); - - Console.WriteLine($"Current discount: {theCustomer.ComputeLoyaltyDiscount()}"); - - // - ICustomer.SetLoyaltyThresholds(new TimeSpan(30, 0, 0, 0), 1, 0.25m); - Console.WriteLine($"Current discount: {theCustomer.ComputeLoyaltyDiscount()}"); - // - } - } -} diff --git a/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/SampleCustomer.cs b/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/SampleCustomer.cs deleted file mode 100644 index ea18d17c7c199..0000000000000 --- a/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/SampleCustomer.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace customer_relationship -{ - public class SampleCustomer : ICustomer - { - public SampleCustomer(string name, DateTime dateJoined) => - (Name, DateJoined) = (name, dateJoined); - - private List allOrders = new List(); - - public IEnumerable PreviousOrders => allOrders; - - public DateTime DateJoined { get; } - - public DateTime? LastOrder { get; private set; } - - public string Name { get; } - - private Dictionary reminders = new Dictionary(); - public IDictionary Reminders => reminders; - - public void AddOrder(IOrder order) - { - if (order.Purchased > (LastOrder ?? DateTime.MinValue)) - LastOrder = order.Purchased; - allOrders.Add(order); - } - - // - public decimal ComputeLoyaltyDiscount() - { - if (PreviousOrders.Any() == false) - return 0.50m; - else - return ICustomer.DefaultLoyaltyDiscount(this); - } - // - } -} diff --git a/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/SampleOrder.cs b/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/SampleOrder.cs deleted file mode 100644 index a0b3bbfc3e57e..0000000000000 --- a/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/SampleOrder.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace customer_relationship -{ - public class SampleOrder : IOrder - { - public SampleOrder(DateTime purchase, decimal cost) => - (Purchased, Cost) = (purchase, cost); - - public DateTime Purchased { get; } - - public decimal Cost { get; } - } -} diff --git a/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/customer-relationship.csproj b/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/customer-relationship.csproj deleted file mode 100644 index d5421a65e5e51..0000000000000 --- a/samples/snippets/csharp/tutorials/default-interface-members-versions/finished/customer-relationship/customer-relationship.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - - Exe - net6.0 - customer_relationship - 8.0 - - - diff --git a/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/ICustomer.cs b/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/ICustomer.cs deleted file mode 100644 index 687435f9b8ea6..0000000000000 --- a/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/ICustomer.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace customer_relationship -{ - // - public interface ICustomer - { - IEnumerable PreviousOrders { get; } - - DateTime DateJoined { get; } - DateTime? LastOrder { get; } - string Name { get; } - IDictionary Reminders { get; } - } - // -} diff --git a/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/IOrder.cs b/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/IOrder.cs deleted file mode 100644 index da8cd410fc9c4..0000000000000 --- a/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/IOrder.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace customer_relationship -{ - // - public interface IOrder - { - DateTime Purchased { get; } - decimal Cost { get; } - } - // -} diff --git a/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/Program.cs b/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/Program.cs deleted file mode 100644 index 4a15b010c6d90..0000000000000 --- a/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/Program.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; -using System.Linq; - -namespace customer_relationship -{ - class Program - { - static void Main(string[] args) - { - SampleCustomer c = new SampleCustomer("customer one", new DateTime(2010, 5, 31)) - { - Reminders = - { - { new DateTime(2010, 08, 12), "childs's birthday" }, - { new DateTime(1012, 11, 15), "anniversary" } - } - }; - - SampleOrder o = new SampleOrder(new DateTime(2012, 6, 1), 5m); - c.AddOrder(o); - - o = new SampleOrder(new DateTime(2103, 7, 4), 25m); - c.AddOrder(o); - - Console.WriteLine($"Data about {c.Name}"); - Console.WriteLine($"Joined on {c.DateJoined}. Made {c.PreviousOrders.Count()} orders, the last on {c.LastOrder}"); - Console.WriteLine("Reminders:"); - foreach(var item in c.Reminders) - { - Console.WriteLine($"\t{item.Value} on {item.Key}"); - } - foreach (IOrder order in c.PreviousOrders) - Console.WriteLine($"Order on {order.Purchased} for {order.Cost}"); - } - } -} diff --git a/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/SampleCustomer.cs b/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/SampleCustomer.cs deleted file mode 100644 index 471e7acc5849c..0000000000000 --- a/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/SampleCustomer.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace customer_relationship -{ - public class SampleCustomer : ICustomer - { - public SampleCustomer(string name, DateTime dateJoined) => - (Name, DateJoined) = (name, dateJoined); - - private List allOrders = new List(); - - public IEnumerable PreviousOrders => allOrders; - - public DateTime DateJoined { get; } - - public DateTime? LastOrder { get; private set; } - - public string Name { get; } - - private Dictionary reminders = new Dictionary(); - public IDictionary Reminders => reminders; - - public void AddOrder(IOrder order) - { - if (order.Purchased > (LastOrder ?? DateTime.MinValue)) - LastOrder = order.Purchased; - allOrders.Add(order); - } - } -} diff --git a/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/SampleOrder.cs b/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/SampleOrder.cs deleted file mode 100644 index 7a521dea087dc..0000000000000 --- a/samples/snippets/csharp/tutorials/default-interface-members-versions/starter/customer-relationship/SampleOrder.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace customer_relationship -{ - public class SampleOrder : IOrder - { - public SampleOrder(DateTime purchase, decimal cost) => - (Purchased, Cost) = (purchase, cost); - - public DateTime Purchased { get; } - - public decimal Cost { get; } - } -} From cd69606b4520e3c61655872babab2d6cd83c0caf Mon Sep 17 00:00:00 2001 From: vcrobe Date: Wed, 2 Nov 2022 10:28:34 -0400 Subject: [PATCH 20/24] Update consuming-the-task-based-asynchronous-pattern.md (#32114) * Update consuming-the-task-based-asynchronous-pattern.md - I think it is better to highlight the note at line 93: "Cancellation requests may be initiated from any thread." - At line 146 we're talking about the same method as another overloaded version but in fact is the same overload method. * Update consuming-the-task-based-asynchronous-pattern.md Fixed linter error on line 94 --- .../consuming-the-task-based-asynchronous-pattern.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/standard/asynchronous-programming-patterns/consuming-the-task-based-asynchronous-pattern.md b/docs/standard/asynchronous-programming-patterns/consuming-the-task-based-asynchronous-pattern.md index 3f2dea20d9955..f38979cd279fb 100644 --- a/docs/standard/asynchronous-programming-patterns/consuming-the-task-based-asynchronous-pattern.md +++ b/docs/standard/asynchronous-programming-patterns/consuming-the-task-based-asynchronous-pattern.md @@ -90,7 +90,8 @@ var cts = new CancellationTokenSource(); cts.Cancel(); ``` - Cancellation requests may be initiated from any thread. +> [!IMPORTANT] +> Cancellation requests may be initiated from any thread. You can pass the value to any method that accepts a cancellation token to indicate that cancellation will never be requested. This causes the property to return `false`, and the called method can optimize accordingly. For testing purposes, you can also pass in a pre-canceled cancellation token that is instantiated by using the constructor that accepts a Boolean value to indicate whether the token should start in an already-canceled or not-cancelable state. @@ -142,7 +143,7 @@ public async void button1_Click(object sender, EventArgs e) } ``` - Some of these methods, such as the overload, exist as shorthand for the method. Other overloads, such as , enable you to use await within the offloaded work, for example: + Some of these methods, such as the overload, exist as shorthand for the method. This overload enable you to use await within the offloaded work, for example: ```csharp public async void button1_Click(object sender, EventArgs e) From d667779c8403189462e3140c9abc5a0c2b25ee0c Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Wed, 2 Nov 2022 11:28:55 -0400 Subject: [PATCH 21/24] Update package index with latest published versions (#32142) --- docs/azure/includes/dotnet-all.md | 8 ++++---- docs/azure/includes/dotnet-new.md | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/azure/includes/dotnet-all.md b/docs/azure/includes/dotnet-all.md index 3a201b0f48908..27d69d38177e8 100644 --- a/docs/azure/includes/dotnet-all.md +++ b/docs/azure/includes/dotnet-all.md @@ -133,7 +133,7 @@ | Resource Management - Billing | NuGet [1.0.0-beta.1](https://www.nuget.org/packages/Azure.ResourceManager.Billing/1.0.0-beta.1) | | GitHub [1.0.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Billing_1.0.0-beta.1/sdk/billing/Azure.ResourceManager.Billing/) | | Resource Management - Cdn | NuGet [1.0.1](https://www.nuget.org/packages/Azure.ResourceManager.Cdn/1.0.1) | [docs](/dotnet/api/overview/azure/ResourceManager.Cdn-readme) | GitHub [1.0.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Cdn_1.0.1/sdk/cdn/Azure.ResourceManager.Cdn/) | | Resource Management - Change Analysis | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.ChangeAnalysis/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.ChangeAnalysis-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.ChangeAnalysis_1.0.0/sdk/changeanalysis/Azure.ResourceManager.ChangeAnalysis/) | -| Resource Management - Cognitive Services | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.CognitiveServices/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.CognitiveServices-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.CognitiveServices_1.0.0/sdk/cognitiveservices/Azure.ResourceManager.CognitiveServices/) | +| Resource Management - Cognitive Services | NuGet [1.1.0](https://www.nuget.org/packages/Azure.ResourceManager.CognitiveServices/1.1.0) | [docs](/dotnet/api/overview/azure/ResourceManager.CognitiveServices-readme) | GitHub [1.1.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.CognitiveServices_1.1.0/sdk/cognitiveservices/Azure.ResourceManager.CognitiveServices/) | | Resource Management - Communication | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.Communication/1.0.0)
NuGet [1.1.0-beta.5](https://www.nuget.org/packages/Azure.ResourceManager.Communication/1.1.0-beta.5) | [docs](/dotnet/api/overview/azure/ResourceManager.Communication-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Communication_1.0.0/sdk/communication/Azure.ResourceManager.Communication/)
GitHub [1.1.0-beta.5](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Communication_1.1.0-beta.5/sdk/communication/Azure.ResourceManager.Communication/) | | Resource Management - Compute | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.Compute/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.Compute-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Compute_1.0.0/sdk/compute/Azure.ResourceManager.Compute/) | | Resource Management - Confidential Ledger | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.ConfidentialLedger/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.ConfidentialLedger-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.ConfidentialLedger_1.0.0/sdk/confidentialledger/Azure.ResourceManager.ConfidentialLedger/) | @@ -189,7 +189,7 @@ | Resource Management - Monitor | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.Monitor/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.Monitor-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Monitor_1.0.0/sdk/monitor/Azure.ResourceManager.Monitor/) | | Resource Management - MySql | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.MySql/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.MySql-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.MySql_1.0.0/sdk/mysql/Azure.ResourceManager.MySql/) | | Resource Management - Net App | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.NetApp/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.NetApp-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NetApp_1.0.0/sdk/netapp/Azure.ResourceManager.NetApp/) | -| Resource Management - Network | NuGet [1.0.1](https://www.nuget.org/packages/Azure.ResourceManager.Network/1.0.1) | [docs](/dotnet/api/overview/azure/ResourceManager.Network-readme) | GitHub [1.0.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Network_1.0.1/sdk/network/Azure.ResourceManager.Network/) | +| Resource Management - Network | NuGet [1.1.0](https://www.nuget.org/packages/Azure.ResourceManager.Network/1.1.0) | [docs](/dotnet/api/overview/azure/ResourceManager.Network-readme) | GitHub [1.1.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Network_1.1.0/sdk/network/Azure.ResourceManager.Network/) | | Resource Management - Network Function | NuGet [1.0.0-beta.1](https://www.nuget.org/packages/Azure.ResourceManager.NetworkFunction/1.0.0-beta.1) | | GitHub [1.0.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NetworkFunction_1.0.0-beta.1/sdk/networkfunction/Azure.ResourceManager.NetworkFunction/) | | Resource Management - Notification Hubs | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.NotificationHubs/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.NotificationHubs-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NotificationHubs_1.0.0/sdk/notificationhubs/Azure.ResourceManager.NotificationHubs/) | | Resource Management - Orbital | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.Orbital/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.Orbital-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Orbital_1.0.0/sdk/orbital/Azure.ResourceManager.Orbital/) | @@ -851,7 +851,7 @@ | Resource Management - Billing | NuGet [1.0.0-beta.1](https://www.nuget.org/packages/Azure.ResourceManager.Billing/1.0.0-beta.1) | | GitHub [1.0.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Billing_1.0.0-beta.1/sdk/billing/Azure.ResourceManager.Billing/) | | Resource Management - Cdn | NuGet [1.0.1](https://www.nuget.org/packages/Azure.ResourceManager.Cdn/1.0.1) | [docs](/dotnet/api/overview/azure/ResourceManager.Cdn-readme) | GitHub [1.0.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Cdn_1.0.1/sdk/cdn/Azure.ResourceManager.Cdn/) | | Resource Management - Change Analysis | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.ChangeAnalysis/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.ChangeAnalysis-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.ChangeAnalysis_1.0.0/sdk/changeanalysis/Azure.ResourceManager.ChangeAnalysis/) | -| Resource Management - Cognitive Services | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.CognitiveServices/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.CognitiveServices-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.CognitiveServices_1.0.0/sdk/cognitiveservices/Azure.ResourceManager.CognitiveServices/) | +| Resource Management - Cognitive Services | NuGet [1.1.0](https://www.nuget.org/packages/Azure.ResourceManager.CognitiveServices/1.1.0) | [docs](/dotnet/api/overview/azure/ResourceManager.CognitiveServices-readme) | GitHub [1.1.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.CognitiveServices_1.1.0/sdk/cognitiveservices/Azure.ResourceManager.CognitiveServices/) | | Resource Management - Communication | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.Communication/1.0.0)
NuGet [1.1.0-beta.5](https://www.nuget.org/packages/Azure.ResourceManager.Communication/1.1.0-beta.5) | [docs](/dotnet/api/overview/azure/ResourceManager.Communication-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Communication_1.0.0/sdk/communication/Azure.ResourceManager.Communication/)
GitHub [1.1.0-beta.5](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Communication_1.1.0-beta.5/sdk/communication/Azure.ResourceManager.Communication/) | | Resource Management - Compute | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.Compute/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.Compute-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Compute_1.0.0/sdk/compute/Azure.ResourceManager.Compute/) | | Resource Management - Confidential Ledger | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.ConfidentialLedger/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.ConfidentialLedger-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.ConfidentialLedger_1.0.0/sdk/confidentialledger/Azure.ResourceManager.ConfidentialLedger/) | @@ -907,7 +907,7 @@ | Resource Management - Monitor | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.Monitor/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.Monitor-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Monitor_1.0.0/sdk/monitor/Azure.ResourceManager.Monitor/) | | Resource Management - MySql | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.MySql/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.MySql-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.MySql_1.0.0/sdk/mysql/Azure.ResourceManager.MySql/) | | Resource Management - Net App | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.NetApp/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.NetApp-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NetApp_1.0.0/sdk/netapp/Azure.ResourceManager.NetApp/) | -| Resource Management - Network | NuGet [1.0.1](https://www.nuget.org/packages/Azure.ResourceManager.Network/1.0.1) | [docs](/dotnet/api/overview/azure/ResourceManager.Network-readme) | GitHub [1.0.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Network_1.0.1/sdk/network/Azure.ResourceManager.Network/) | +| Resource Management - Network | NuGet [1.1.0](https://www.nuget.org/packages/Azure.ResourceManager.Network/1.1.0) | [docs](/dotnet/api/overview/azure/ResourceManager.Network-readme) | GitHub [1.1.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Network_1.1.0/sdk/network/Azure.ResourceManager.Network/) | | Resource Management - Network Function | NuGet [1.0.0-beta.1](https://www.nuget.org/packages/Azure.ResourceManager.NetworkFunction/1.0.0-beta.1) | | GitHub [1.0.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NetworkFunction_1.0.0-beta.1/sdk/networkfunction/Azure.ResourceManager.NetworkFunction/) | | Resource Management - Notification Hubs | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.NotificationHubs/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.NotificationHubs-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NotificationHubs_1.0.0/sdk/notificationhubs/Azure.ResourceManager.NotificationHubs/) | | Resource Management - Orbital | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.Orbital/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.Orbital-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Orbital_1.0.0/sdk/orbital/Azure.ResourceManager.Orbital/) | diff --git a/docs/azure/includes/dotnet-new.md b/docs/azure/includes/dotnet-new.md index dce549a0826cf..47866328aedbb 100644 --- a/docs/azure/includes/dotnet-new.md +++ b/docs/azure/includes/dotnet-new.md @@ -133,7 +133,7 @@ | Resource Management - Billing | NuGet [1.0.0-beta.1](https://www.nuget.org/packages/Azure.ResourceManager.Billing/1.0.0-beta.1) | | GitHub [1.0.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Billing_1.0.0-beta.1/sdk/billing/Azure.ResourceManager.Billing/) | | Resource Management - Cdn | NuGet [1.0.1](https://www.nuget.org/packages/Azure.ResourceManager.Cdn/1.0.1) | [docs](/dotnet/api/overview/azure/ResourceManager.Cdn-readme) | GitHub [1.0.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Cdn_1.0.1/sdk/cdn/Azure.ResourceManager.Cdn/) | | Resource Management - Change Analysis | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.ChangeAnalysis/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.ChangeAnalysis-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.ChangeAnalysis_1.0.0/sdk/changeanalysis/Azure.ResourceManager.ChangeAnalysis/) | -| Resource Management - Cognitive Services | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.CognitiveServices/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.CognitiveServices-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.CognitiveServices_1.0.0/sdk/cognitiveservices/Azure.ResourceManager.CognitiveServices/) | +| Resource Management - Cognitive Services | NuGet [1.1.0](https://www.nuget.org/packages/Azure.ResourceManager.CognitiveServices/1.1.0) | [docs](/dotnet/api/overview/azure/ResourceManager.CognitiveServices-readme) | GitHub [1.1.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.CognitiveServices_1.1.0/sdk/cognitiveservices/Azure.ResourceManager.CognitiveServices/) | | Resource Management - Communication | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.Communication/1.0.0)
NuGet [1.1.0-beta.5](https://www.nuget.org/packages/Azure.ResourceManager.Communication/1.1.0-beta.5) | [docs](/dotnet/api/overview/azure/ResourceManager.Communication-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Communication_1.0.0/sdk/communication/Azure.ResourceManager.Communication/)
GitHub [1.1.0-beta.5](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Communication_1.1.0-beta.5/sdk/communication/Azure.ResourceManager.Communication/) | | Resource Management - Compute | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.Compute/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.Compute-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Compute_1.0.0/sdk/compute/Azure.ResourceManager.Compute/) | | Resource Management - Confidential Ledger | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.ConfidentialLedger/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.ConfidentialLedger-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.ConfidentialLedger_1.0.0/sdk/confidentialledger/Azure.ResourceManager.ConfidentialLedger/) | @@ -189,7 +189,7 @@ | Resource Management - Monitor | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.Monitor/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.Monitor-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Monitor_1.0.0/sdk/monitor/Azure.ResourceManager.Monitor/) | | Resource Management - MySql | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.MySql/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.MySql-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.MySql_1.0.0/sdk/mysql/Azure.ResourceManager.MySql/) | | Resource Management - Net App | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.NetApp/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.NetApp-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NetApp_1.0.0/sdk/netapp/Azure.ResourceManager.NetApp/) | -| Resource Management - Network | NuGet [1.0.1](https://www.nuget.org/packages/Azure.ResourceManager.Network/1.0.1) | [docs](/dotnet/api/overview/azure/ResourceManager.Network-readme) | GitHub [1.0.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Network_1.0.1/sdk/network/Azure.ResourceManager.Network/) | +| Resource Management - Network | NuGet [1.1.0](https://www.nuget.org/packages/Azure.ResourceManager.Network/1.1.0) | [docs](/dotnet/api/overview/azure/ResourceManager.Network-readme) | GitHub [1.1.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Network_1.1.0/sdk/network/Azure.ResourceManager.Network/) | | Resource Management - Network Function | NuGet [1.0.0-beta.1](https://www.nuget.org/packages/Azure.ResourceManager.NetworkFunction/1.0.0-beta.1) | | GitHub [1.0.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NetworkFunction_1.0.0-beta.1/sdk/networkfunction/Azure.ResourceManager.NetworkFunction/) | | Resource Management - Notification Hubs | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.NotificationHubs/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.NotificationHubs-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NotificationHubs_1.0.0/sdk/notificationhubs/Azure.ResourceManager.NotificationHubs/) | | Resource Management - Orbital | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.Orbital/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.Orbital-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Orbital_1.0.0/sdk/orbital/Azure.ResourceManager.Orbital/) | From f2ce3aa915a9ecb8d4ba3c117d918b7eba39fc34 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 2 Nov 2022 09:43:05 -0700 Subject: [PATCH 22/24] October chores (#32115) --- .../rabbitmq-event-bus-development-test-environment.md | 2 +- docs/csharp/language-reference/compiler-messages/cs8141.md | 2 +- docs/csharp/language-reference/compiler-messages/toc.yml | 2 ++ docs/framework/toc.yml | 2 ++ docs/fundamentals/toc.yml | 2 ++ 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/architecture/microservices/multi-container-microservice-net-applications/rabbitmq-event-bus-development-test-environment.md b/docs/architecture/microservices/multi-container-microservice-net-applications/rabbitmq-event-bus-development-test-environment.md index 8791a9725ef0d..0e1ee511fb6ce 100644 --- a/docs/architecture/microservices/multi-container-microservice-net-applications/rabbitmq-event-bus-development-test-environment.md +++ b/docs/architecture/microservices/multi-container-microservice-net-applications/rabbitmq-event-bus-development-test-environment.md @@ -7,7 +7,7 @@ ms.date: 01/13/2021 [!INCLUDE [download-alert](../includes/download-alert.md)] -We should start by saying that if you create your custom event bus based on [RabbitMQ](https://www.rabbitmq.com/) running in a container, as the eShopOnContainers application does, it should be used only for your development and test environments. Don't use it for your production environment, unless you are building it as a part of a production-ready service bus as described in the [Additional resources section below](/dotnet/architecture/microservices/multi-container-microservice-net-applications/rabbitmq-event-bus-development-test-environment#additional-resources). A simple custom event bus might be missing many production-ready critical features that a commercial service bus has. +We should start by saying that if you create your custom event bus based on [RabbitMQ](https://www.rabbitmq.com/) running in a container, as the eShopOnContainers application does, it should be used only for your development and test environments. Don't use it for your production environment, unless you are building it as a part of a production-ready service bus as described in the [Additional resources section below](rabbitmq-event-bus-development-test-environment.md#additional-resources). A simple custom event bus might be missing many production-ready critical features that a commercial service bus has. One of the event bus custom implementations in eShopOnContainers is basically a library using the RabbitMQ API. (There's another implementation based on Azure Service Bus.) diff --git a/docs/csharp/language-reference/compiler-messages/cs8141.md b/docs/csharp/language-reference/compiler-messages/cs8141.md index c589dd61e1136..8e99744d298ac 100644 --- a/docs/csharp/language-reference/compiler-messages/cs8141.md +++ b/docs/csharp/language-reference/compiler-messages/cs8141.md @@ -13,7 +13,7 @@ The tuple element names in the signature of method must match the tuple element ## Example - The following sample generates CS8141: +The following sample generates CS8141: ```csharp // CS8141.cs (10,27) diff --git a/docs/csharp/language-reference/compiler-messages/toc.yml b/docs/csharp/language-reference/compiler-messages/toc.yml index 3377f330bb778..838f92616fd60 100644 --- a/docs/csharp/language-reference/compiler-messages/toc.yml +++ b/docs/csharp/language-reference/compiler-messages/toc.yml @@ -1623,6 +1623,8 @@ items: href: cs8139.md - name: CS8140 href: cs8140.md + - name: CS8141 + href: cs8141.md - name: CS8145 href: cs8145.md - name: CS8146 diff --git a/docs/framework/toc.yml b/docs/framework/toc.yml index 05301859a6db5..2c6e583e2104c 100644 --- a/docs/framework/toc.yml +++ b/docs/framework/toc.yml @@ -21,6 +21,8 @@ items: items: - name: Windows 11 href: install/on-windows-11.md + - name: Windows Server 2022 + href: install/on-server-2022.md - name: Windows 10 and Windows Server 2016 href: install/on-windows-10.md - name: Windows 8.1 and Windows Server 2012 R2 diff --git a/docs/fundamentals/toc.yml b/docs/fundamentals/toc.yml index a632c4215ce5d..6f176aeab6873 100644 --- a/docs/fundamentals/toc.yml +++ b/docs/fundamentals/toc.yml @@ -2590,6 +2590,8 @@ items: href: networking/network-info.md - name: IPv6 overview href: networking/ipv6-overview.md + - name: Telemetry + href: networking/networking-telemetry.md - name: HTTP items: - name: HTTP support From 9715618baf036319501a6ed9c65f90067749a785 Mon Sep 17 00:00:00 2001 From: Patrick Sadowski Date: Wed, 2 Nov 2022 17:47:16 +0100 Subject: [PATCH 23/24] Fix option heading level (#32123) --- docs/fundamentals/code-analysis/style-rules/ide0049.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/fundamentals/code-analysis/style-rules/ide0049.md b/docs/fundamentals/code-analysis/style-rules/ide0049.md index 35c7fe8e2754a..6be916ad06cb4 100644 --- a/docs/fundamentals/code-analysis/style-rules/ide0049.md +++ b/docs/fundamentals/code-analysis/style-rules/ide0049.md @@ -69,7 +69,7 @@ Private _member As Integer Private _member As Int32 ``` -## dotnet_style_predefined_type_for_member_access +### dotnet_style_predefined_type_for_member_access | Property | Value | Description | | ------------------------ | ---------------------------------------------- | --------------------------------------------------------- | From be87042b88e633850d18605a8b2dc86b49ba9409 Mon Sep 17 00:00:00 2001 From: Scott Addie <10702007+scottaddie@users.noreply.github.com> Date: Wed, 2 Nov 2022 19:57:34 -0500 Subject: [PATCH 24/24] Add missing NuGet package installation step (#32151) --- docs/azure/sdk/logging.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/azure/sdk/logging.md b/docs/azure/sdk/logging.md index 070aa065aeed9..6ec5e9b57c05a 100644 --- a/docs/azure/sdk/logging.md +++ b/docs/azure/sdk/logging.md @@ -1,7 +1,7 @@ --- title: Logging with the Azure SDK for .NET description: Learn how to enable logging with the Azure SDK for .NET client libraries -ms.date: 08/26/2022 +ms.date: 11/02/2022 ms.custom: devx-track-dotnet ms.author: casoper author: camsoper @@ -118,6 +118,12 @@ The following table depicts how the Azure SDK for .NET `EventLevel` maps to the Using the Azure Service Bus library as an example, complete the following steps: +1. Install the [Microsoft.Extensions.Azure](https://www.nuget.org/packages/Microsoft.Extensions.Azure) NuGet package: + + ```dotnetcli + dotnet add package Microsoft.Extensions.Azure + ``` + 1. Register the Azure SDK library's client via a call to the extension method: ```csharp @@ -159,6 +165,12 @@ There are scenarios in which [registering an Azure SDK library's client with the In these scenarios, complete the following steps: +1. Install the [Microsoft.Extensions.Azure](https://www.nuget.org/packages/Microsoft.Extensions.Azure) NuGet package: + + ```dotnetcli + dotnet add package Microsoft.Extensions.Azure + ``` + 1. Register the log forwarder service as a singleton in the DI container: :::code language="csharp" source="snippets/logging/Program.cs" id="RegisterServiceWithDI" highlight="8":::