Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions docs/azure/includes/dotnet-all.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/azure/includes/dotnet-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
| Provisioning - App Service | NuGet [1.3.1](https://www.nuget.org/packages/Azure.Provisioning.AppService/1.3.1)<br>NuGet [1.4.0-beta.2](https://www.nuget.org/packages/Azure.Provisioning.AppService/1.4.0-beta.2) | [docs](/dotnet/api/overview/azure/Provisioning.AppService-readme) | GitHub [1.3.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Provisioning.AppService_1.3.1/sdk/provisioning/Azure.Provisioning.AppService/)<br>GitHub [1.4.0-beta.2](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Provisioning.AppService_1.4.0-beta.2/sdk/provisioning/Azure.Provisioning.AppService/) |
| Provisioning - Application Insights | NuGet [1.1.0](https://www.nuget.org/packages/Azure.Provisioning.ApplicationInsights/1.1.0)<br>NuGet [1.2.0-beta.1](https://www.nuget.org/packages/Azure.Provisioning.ApplicationInsights/1.2.0-beta.1) | [docs](/dotnet/api/overview/azure/Provisioning.ApplicationInsights-readme) | GitHub [1.1.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Provisioning.ApplicationInsights_1.1.0/sdk/provisioning/Azure.Provisioning.ApplicationInsights/)<br>GitHub [1.2.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Provisioning.ApplicationInsights_1.2.0-beta.1/sdk/provisioning/Azure.Provisioning.ApplicationInsights/) |
| Provisioning - Batch | NuGet [1.0.0-beta.1](https://www.nuget.org/packages/Azure.Provisioning.Batch/1.0.0-beta.1) | [docs](/dotnet/api/overview/azure/Provisioning.Batch-readme?view=azure-dotnet-preview&amp;preserve-view=true) | GitHub [1.0.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Provisioning.Batch_1.0.0-beta.1/sdk/batch/Azure.Provisioning.Batch/) |
| Provisioning - Cdn | NuGet [1.0.0-beta.2](https://www.nuget.org/packages/Azure.Provisioning.Cdn/1.0.0-beta.2) | [docs](/dotnet/api/overview/azure/Provisioning.Cdn-readme?view=azure-dotnet-preview&amp;preserve-view=true) | GitHub [1.0.0-beta.2](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Provisioning.Cdn_1.0.0-beta.2/sdk/provisioning/Azure.Provisioning.Cdn/) |
| Provisioning - Cdn | NuGet [1.0.0-beta.2](https://www.nuget.org/packages/Azure.Provisioning.Cdn/1.0.0-beta.2) | [docs](/dotnet/api/overview/azure/Provisioning.Cdn-readme?view=azure-dotnet-preview&amp;preserve-view=true) | GitHub [1.0.0-beta.2](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Provisioning.Cdn_1.0.0-beta.2/sdk/cdn/Azure.Provisioning.Cdn/) |
| Provisioning - Cognitive Services | NuGet [1.2.0](https://www.nuget.org/packages/Azure.Provisioning.CognitiveServices/1.2.0) | [docs](/dotnet/api/overview/azure/Provisioning.CognitiveServices-readme) | GitHub [1.2.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Provisioning.CognitiveServices_1.2.0/sdk/provisioning/Azure.Provisioning.CognitiveServices/) |
| Provisioning - Communication | NuGet [1.0.0-beta.4](https://www.nuget.org/packages/Azure.Provisioning.Communication/1.0.0-beta.4) | [docs](/dotnet/api/overview/azure/Provisioning.Communication-readme?view=azure-dotnet-preview&amp;preserve-view=true) | GitHub [1.0.0-beta.4](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Provisioning.Communication_1.0.0-beta.4/sdk/provisioning/Azure.Provisioning.Communication/) |
| Provisioning - Compute | NuGet [1.0.0-beta.1](https://www.nuget.org/packages/Azure.Provisioning.Compute/1.0.0-beta.1) | [docs](/dotnet/api/overview/azure/Provisioning.Compute-readme?view=azure-dotnet-preview&amp;preserve-view=true) | GitHub [1.0.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.Provisioning.Compute_1.0.0-beta.1/sdk/compute/Azure.Provisioning.Compute/) |
Expand Down Expand Up @@ -302,7 +302,7 @@
| Resource Management - Event Hubs | NuGet [1.2.1](https://www.nuget.org/packages/Azure.ResourceManager.EventHubs/1.2.1)<br>NuGet [1.3.0-beta.1](https://www.nuget.org/packages/Azure.ResourceManager.EventHubs/1.3.0-beta.1) | [docs](/dotnet/api/overview/azure/ResourceManager.EventHubs-readme) | GitHub [1.2.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.EventHubs_1.2.1/sdk/eventhub/Azure.ResourceManager.EventHubs/)<br>GitHub [1.3.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.EventHubs_1.3.0-beta.1/sdk/eventhub/Azure.ResourceManager.EventHubs/) |
| Resource Management - Extended Location | NuGet [1.1.2](https://www.nuget.org/packages/Azure.ResourceManager.ExtendedLocations/1.1.2) | [docs](/dotnet/api/overview/azure/ResourceManager.ExtendedLocations-readme) | GitHub [1.1.2](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.ExtendedLocations_1.1.2/sdk/extendedlocation/Azure.ResourceManager.ExtendedLocations/) |
| Resource Management - Fabric | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.Fabric/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.Fabric-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Fabric_1.0.0/sdk/fabric/Azure.ResourceManager.Fabric/) |
| Resource Management - Fileshares | NuGet [1.0.0-beta.2](https://www.nuget.org/packages/Azure.ResourceManager.FileShares/1.0.0-beta.2) | [docs](/dotnet/api/overview/azure/ResourceManager.FileShares-readme?view=azure-dotnet-preview&amp;preserve-view=true) | GitHub [1.0.0-beta.2](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.FileShares_1.0.0-beta.2/sdk/fileshares/Azure.ResourceManager.FileShares/) |
| Resource Management - Fileshares | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.FileShares/1.0.0)<br>NuGet [1.0.0-beta.2](https://www.nuget.org/packages/Azure.ResourceManager.FileShares/1.0.0-beta.2) | [docs](/dotnet/api/overview/azure/ResourceManager.FileShares-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.FileShares_1.0.0/sdk/fileshares/Azure.ResourceManager.FileShares/)<br>GitHub [1.0.0-beta.2](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.FileShares_1.0.0-beta.2/sdk/fileshares/Azure.ResourceManager.FileShares/) |
| Resource Management - Fluid Relay | NuGet [1.1.2](https://www.nuget.org/packages/Azure.ResourceManager.FluidRelay/1.1.2) | [docs](/dotnet/api/overview/azure/ResourceManager.FluidRelay-readme) | GitHub [1.1.2](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.FluidRelay_1.1.2/sdk/fluidrelay/Azure.ResourceManager.FluidRelay/) |
| Resource Management - Front Door | NuGet [1.4.1](https://www.nuget.org/packages/Azure.ResourceManager.FrontDoor/1.4.1) | [docs](/dotnet/api/overview/azure/ResourceManager.FrontDoor-readme) | GitHub [1.4.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.FrontDoor_1.4.1/sdk/frontdoor/Azure.ResourceManager.FrontDoor/) |
| Resource Management - Graph Services | NuGet [1.1.3](https://www.nuget.org/packages/Azure.ResourceManager.GraphServices/1.1.3) | [docs](/dotnet/api/overview/azure/ResourceManager.GraphServices-readme) | GitHub [1.1.3](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.GraphServices_1.1.3/sdk/graphservices/Azure.ResourceManager.GraphServices/) |
Expand Down Expand Up @@ -359,7 +359,7 @@
| Resource Management - Monitor | NuGet [1.3.1](https://www.nuget.org/packages/Azure.ResourceManager.Monitor/1.3.1)<br>NuGet [1.4.0-beta.4](https://www.nuget.org/packages/Azure.ResourceManager.Monitor/1.4.0-beta.4) | [docs](/dotnet/api/overview/azure/ResourceManager.Monitor-readme) | GitHub [1.3.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Monitor_1.3.1/sdk/monitor/Azure.ResourceManager.Monitor/)<br>GitHub [1.4.0-beta.4](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Monitor_1.4.0-beta.4/sdk/monitor/Azure.ResourceManager.Monitor/) |
| Resource Management - MySQL | NuGet [1.2.0](https://www.nuget.org/packages/Azure.ResourceManager.MySql/1.2.0) | [docs](/dotnet/api/overview/azure/ResourceManager.MySql-readme) | GitHub [1.2.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.MySql_1.2.0/sdk/mysql/Azure.ResourceManager.MySql/) |
| Resource Management - Neon Postgres | NuGet [1.0.0](https://www.nuget.org/packages/Azure.ResourceManager.NeonPostgres/1.0.0) | [docs](/dotnet/api/overview/azure/ResourceManager.NeonPostgres-readme) | GitHub [1.0.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NeonPostgres_1.0.0/sdk/neonpostgres/Azure.ResourceManager.NeonPostgres/) |
| Resource Management - NetApp Files | NuGet [1.15.0](https://www.nuget.org/packages/Azure.ResourceManager.NetApp/1.15.0)<br>NuGet [1.16.0-beta.2](https://www.nuget.org/packages/Azure.ResourceManager.NetApp/1.16.0-beta.2) | [docs](/dotnet/api/overview/azure/ResourceManager.NetApp-readme) | GitHub [1.15.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NetApp_1.15.0/sdk/netapp/Azure.ResourceManager.NetApp/)<br>GitHub [1.16.0-beta.2](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NetApp_1.16.0-beta.2/sdk/netapp/Azure.ResourceManager.NetApp/) |
| Resource Management - NetApp Files | NuGet [1.16.0](https://www.nuget.org/packages/Azure.ResourceManager.NetApp/1.16.0) | [docs](/dotnet/api/overview/azure/ResourceManager.NetApp-readme) | GitHub [1.16.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NetApp_1.16.0/sdk/netapp/Azure.ResourceManager.NetApp/) |
| Resource Management - Network | NuGet [1.15.0](https://www.nuget.org/packages/Azure.ResourceManager.Network/1.15.0) | [docs](/dotnet/api/overview/azure/ResourceManager.Network-readme) | GitHub [1.15.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Network_1.15.0/sdk/network/Azure.ResourceManager.Network/) |
| Resource Management - Network Analytics | NuGet [1.0.1](https://www.nuget.org/packages/Azure.ResourceManager.NetworkAnalytics/1.0.1) | [docs](/dotnet/api/overview/azure/ResourceManager.NetworkAnalytics-readme) | GitHub [1.0.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NetworkAnalytics_1.0.1/sdk/networkanalytics/Azure.ResourceManager.NetworkAnalytics/) |
| Resource Management - Network Cloud | NuGet [1.3.0](https://www.nuget.org/packages/Azure.ResourceManager.NetworkCloud/1.3.0) | [docs](/dotnet/api/overview/azure/ResourceManager.NetworkCloud-readme) | GitHub [1.3.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.NetworkCloud_1.3.0/sdk/networkcloud/Azure.ResourceManager.NetworkCloud/) |
Expand Down Expand Up @@ -388,7 +388,7 @@
| Resource Management - Qumulo | NuGet [1.2.0](https://www.nuget.org/packages/Azure.ResourceManager.Qumulo/1.2.0) | [docs](/dotnet/api/overview/azure/ResourceManager.Qumulo-readme) | GitHub [1.2.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Qumulo_1.2.0/sdk/qumulo/Azure.ResourceManager.Qumulo/) |
| Resource Management - Quota | NuGet [1.2.0](https://www.nuget.org/packages/Azure.ResourceManager.Quota/1.2.0) | [docs](/dotnet/api/overview/azure/ResourceManager.Quota-readme) | GitHub [1.2.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Quota_1.2.0/sdk/quota/Azure.ResourceManager.Quota/) |
| Resource Management - Recovery Services | NuGet [1.2.0](https://www.nuget.org/packages/Azure.ResourceManager.RecoveryServices/1.2.0) | [docs](/dotnet/api/overview/azure/ResourceManager.RecoveryServices-readme) | GitHub [1.2.0](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.RecoveryServices_1.2.0/sdk/recoveryservices/Azure.ResourceManager.RecoveryServices/) |
| Resource Management - Recovery Services Backup | NuGet [1.3.1](https://www.nuget.org/packages/Azure.ResourceManager.RecoveryServicesBackup/1.3.1) | [docs](/dotnet/api/overview/azure/ResourceManager.RecoveryServicesBackup-readme) | GitHub [1.3.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.RecoveryServicesBackup_1.3.1/sdk/recoveryservices-backup/Azure.ResourceManager.RecoveryServicesBackup/) |
| Resource Management - Recovery Services Backup | NuGet [1.3.1](https://www.nuget.org/packages/Azure.ResourceManager.RecoveryServicesBackup/1.3.1)<br>NuGet [1.4.0-beta.1](https://www.nuget.org/packages/Azure.ResourceManager.RecoveryServicesBackup/1.4.0-beta.1) | [docs](/dotnet/api/overview/azure/ResourceManager.RecoveryServicesBackup-readme) | GitHub [1.3.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.RecoveryServicesBackup_1.3.1/sdk/recoveryservices-backup/Azure.ResourceManager.RecoveryServicesBackup/)<br>GitHub [1.4.0-beta.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.RecoveryServicesBackup_1.4.0-beta.1/sdk/recoveryservices-backup/Azure.ResourceManager.RecoveryServicesBackup/) |
| Resource Management - Recovery Services Data Replication | NuGet [1.0.1](https://www.nuget.org/packages/Azure.ResourceManager.RecoveryServicesDataReplication/1.0.1) | [docs](/dotnet/api/overview/azure/ResourceManager.RecoveryServicesDataReplication-readme) | GitHub [1.0.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.RecoveryServicesDataReplication_1.0.1/sdk/recoveryservices-datareplication/Azure.ResourceManager.RecoveryServicesDataReplication/) |
| Resource Management - Recovery Services Site Recovery | NuGet [1.3.1](https://www.nuget.org/packages/Azure.ResourceManager.RecoveryServicesSiteRecovery/1.3.1) | [docs](/dotnet/api/overview/azure/ResourceManager.RecoveryServicesSiteRecovery-readme) | GitHub [1.3.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.RecoveryServicesSiteRecovery_1.3.1/sdk/recoveryservices-siterecovery/Azure.ResourceManager.RecoveryServicesSiteRecovery/) |
| Resource Management - Redis | NuGet [1.5.1](https://www.nuget.org/packages/Azure.ResourceManager.Redis/1.5.1) | [docs](/dotnet/api/overview/azure/ResourceManager.Redis-readme) | GitHub [1.5.1](https://github.com/Azure/azure-sdk-for-net/tree/Azure.ResourceManager.Redis_1.5.1/sdk/redis/Azure.ResourceManager.Redis/) |
Expand Down
72 changes: 72 additions & 0 deletions docs/csharp/fundamentals/null-safety/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
title: "Null safety in C#"
description: Learn how C# helps you write null-safe code using nullable value types, nullable reference types, and null operators.
ms.date: 04/30/2026
ms.topic: overview
ai-usage: ai-assisted
---

# C# null safety

> [!TIP]
> This article is part of the **Fundamentals** section for developers who already know at least one programming language and are learning C#. If you're new to programming, start with the [Get started](../../tour-of-csharp/tutorials/index.md) tutorials first.
>
> **Coming from Java or C++?** C# provides compile-time null safety through nullable reference types. The goal is similar to Java's `@NonNull` annotations but enforced by the compiler. C# also has dedicated operators like `?.` and `??` that make null-safe expressions concise.

`null` represents the absence of a value. When you try to access a member on a `null` reference, by calling a method or reading a property, the runtime throws a <xref:System.NullReferenceException>:

:::code language="csharp" source="snippets/null-safety-overview/Program.cs" ID="NullReferenceDemo":::

C# gives you three complementary tools to write null-safe code:

- **Nullable value types**: let a value type such as `int` or `bool` also hold `null`
- **Nullable reference types**: let the compiler track whether a reference might be `null`
- **Null operators**: express null-safe access and fallback logic concisely

## Nullable value types

Value types such as `int`, `double`, and `bool` can't hold `null` by default. Add `?` to the type name to create a *nullable value type* that holds either a value or `null`:

:::code language="csharp" source="snippets/null-safety-overview/Program.cs" ID="NvtIntro":::

Nullable value types are useful when an underlying value type needs to represent "no data." Common scenarios include database columns that might be absent, optional configuration settings, and sensor readings that aren't captured yet.

For full coverage of declaration, checking, and conversion, see [Nullable value types](nullable-value-types.md).

## Nullable reference types

Reference types, such as `string`, arrays, and class instances, can hold `null` at runtime. *Nullable reference types* is a compiler feature that makes null intent explicit and catches mistakes at compile time.

By using the `?` annotation, you declare your intent:

- `string?` — this reference *might* be `null`; the compiler warns if you dereference it without checking first
- `string` — this reference *should not* be `null`; the compiler warns if you assign `null` to it

:::code language="csharp" source="snippets/null-safety-overview/Program.cs" ID="NrtIntro":::

All .NET projects that modern SDK templates create enable nullable reference types by default. For complete guidance on enabling and annotating, see [Nullable reference types](../../nullable-references.md).

## Null operators

C# includes several operators that let you write null-safe code without manual `if`-null guards everywhere:

| Operator | Name | Purpose |
|---------------------------|---------------------------------|--------------------------------------------------------|
| `?.` | Null-conditional member access | Access a member only when the object is non-null |
| `?[]` | Null-conditional indexer access | Access an element only when the collection is non-null |
| `??` | Null-coalescing | Return a fallback value when the expression is `null` |
| `??=` | Null-coalescing assignment | Assign only when the variable is `null` |
| `is null` / `is not null` | Null pattern | Preferred null test |

:::code language="csharp" source="snippets/null-safety-overview/Program.cs" ID="OperatorsQuickRef":::

For detailed examples of each operator, see [Null operators](null-operators.md).

## Nullable value types and nullable reference types serve different purposes

Nullable value types and nullable reference types aren't alternatives. They solve different problems:

- Use `T?` for a value type that needs to represent "no value." For example, use `int?` for an optional database column or `DateTime?` for an event that isn't scheduled yet.
- Use `string?` and other nullable reference annotations to document that a reference *might* be `null`, so the compiler can warn you before a `NullReferenceException` occurs at runtime.

Together, these features and the null operators give you a complete set of tools to write null-safe C# code.
Loading
Loading