var builder = new ConfigurationBuilder() .AddEnvironmentVariables(); var config = builder.Build(); var connectionString = config["ConnectionStrings:MyDatabaseConnection"];
var builder = new ConfigurationBuilder() .AddEnvironmentVariables("MYAPP_"); var config = builder.Build(); var apiToken = config["ApiToken"];In this example, the ConfigurationBuilder reads environment variables that start with "MYAPP_" and stores them in the configuration container. The last line then gets the value of the "ApiToken" key from the container. Overall, these examples demonstrate how the AddEnvironmentVariables method can be used to read and access environment variables as configuration data in an application written in C#.