<!--
title: Feature flag implementation
domain: runtimes
topic: Configurations
language: C#
source: dotnet/runtime
updated: 
url: https://awesomereviewers.com/reviewers/runtime-feature-flag-implementation/
-->

When implementing feature flags, ensure consistency between runtime and compiled scenarios. Feature switches marked with `FeatureSwitchDefinition` must properly return the AppContext switch value when defined:

```csharp
// INCORRECT implementation
[FeatureSwitchDefinition("System.Net.SocketsHttpHandler.Http3Support")]
public static bool IsHttp3Supported => SomeDefaultLogic();

// CORRECT implementation - must use the AppContext switch value
[FeatureSwitchDefinition("System.Net.SocketsHttpHandler.Http3Support")]
public static bool IsHttp3Supported => 
    AppContext.TryGetSwitch("System.Net.SocketsHttpHandler.Http3Support", out var ret) ? ret : SomeDefaultLogic();
```

Consider dead code elimination implications when designing feature flags for AOT scenarios, as behavior differences may arise between `dotnet run` and `dotnet publish`. Avoid adding configuration switches preemptively - only introduce them when there's a demonstrated need from users. For platform-specific features, ensure configuration is properly respected across all supported environments.
