Skip to content

Commit 506c290

Browse files
authored
Use pattern matching in code sample (#9626)
The `null != ...` check looked strange, as it's usually written the other way around in C#. Rather than have a null check, just change this to a type check.
1 parent 02cd139 commit 506c290

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

xml/System.Security.Claims/ClaimsPrincipal.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@
9595
The following example extracts the claims presented by a user in an HTTP request and writes them to the HTTP response. The current user is read from the <xref:System.Web.HttpContext> as a <xref:System.Security.Claims.ClaimsPrincipal>. The claims are then read from it and then are written to the response.
9696
9797
```csharp
98-
ClaimsPrincipal principal = HttpContext.Current.User as ClaimsPrincipal;
99-
if (null != principal)
98+
if (HttpContext.Current.User is ClaimsPrincipal principal)
10099
{
101100
foreach (Claim claim in principal.Claims)
102101
{

0 commit comments

Comments
 (0)