Programming-Idioms

Implementation
C#

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating resource.

Please try to avoid dependencies to third-party libraries and frameworks.

Implementation edit is for fixing errors and enhancing with metadata.

Instead of changing the code of the snippet, consider creating another C# implementation.

Other implementations
  call get_environment_variable ("FOO", length=n, status=st)
  if (st /= 0) then
    foo = "none"
  else
    allocate (character(len=n) :: foo)
    call get_environment_variable ("FOO", value=foo)
  end if 
use 5.010;
my $foo = $ENV{FOO} // 'none';
import "os"
foo, ok := os.LookupEnv("FOO")
if !ok {
	foo = "none"
}
#include <stdlib.h>
const char * foo = getenv("FOO");
if (foo == NULL) foo = "none";
sysutils
var
  foo: string;
begin
  foo := GetEnvironmentVariable('FOO');
  if (foo = '') then foo := 'none';
end.
foo = ENV["FOO"]
import os
try:
    foo = os.environ['FOO']
except KeyError:
    foo = None
from os import getenv
foo = getenv('FOO')
imports System
Dim _foo as String
Try
	foo = Environment.GetEnvironmentVariable("FOO")
Catch ex as Exception
	foo = "none"
End Try
import "os"
foo := os.Getenv("FOO")
if foo == "" {
	foo = "none"
}
Foo = os:getenv("FOO","none").
use std::env;
let foo;
match env::var("FOO") {
    Ok(val) => foo = val,
    Err(_e) => foo = "none".to_string(),
}
#include <cstdlib>
#include <string>
const char* tmp = std::getenv("FOO");
std::string foo = tmp ? std::string(tmp) : "none";
const foo = process.env["FOO"] || "none";