From af3c8ff2da3de6844b8a9d1a517a567ddbbabef8 Mon Sep 17 00:00:00 2001 From: Tom Dykstra Date: Mon, 24 Jul 2023 18:31:46 -0700 Subject: [PATCH] Add IPNetwork.Parse and TryParse to WN (#29905) --- aspnetcore/release-notes/aspnetcore-8.0.md | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/aspnetcore/release-notes/aspnetcore-8.0.md b/aspnetcore/release-notes/aspnetcore-8.0.md index 085252b48b..8266122494 100644 --- a/aspnetcore/release-notes/aspnetcore-8.0.md +++ b/aspnetcore/release-notes/aspnetcore-8.0.md @@ -4,7 +4,7 @@ author: rick-anderson description: Learn about the new features in ASP.NET Core 8.0. ms.author: riande ms.custom: mvc -ms.date: 07/19/2023 +ms.date: 07/24/2023 uid: aspnetcore-8 --- # What's new in ASP.NET Core 8.0 @@ -570,6 +570,36 @@ The debugger display for `WebApplication` highlights important information such For more information about debugging improvements in .NET 8, see GitHub issue [dotnet/aspnetcore 48205](https://github.com/dotnet/aspnetcore/issues/48205). +### `IPNetwork.Parse` and `TryParse` + +The new and methods on add support for creating an `IPNetwork` by using an input string in [CIDR notation](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) or "slash notation". + +Here are IPv4 examples: + +```csharp +// Using Parse +var network = IPNetwork.Parse("192.168.0.1/32"); + +// Using TryParse +bool success = IPNetwork.TryParse("192.168.0.1/32", out var network); + +// Constructor equivalent +var network = new IPNetwork(IPAddress.Parse("192.168.0.1"), 32); +``` + +And here are examples for IPv6: + +```csharp +// Using Parse +var network = IPNetwork.Parse("2001:db8:3c4d::1/128"); + +// Using TryParse +bool success = IPNetwork.TryParse("2001:db8:3c4d::1/128", out var network); + +// Constructor equivalent +var network = new IPNetwork(IPAddress.Parse("2001:db8:3c4d::1"), 128); +``` +