Skip to content

Instantly share code, notes, and snippets.

@biac
Created February 6, 2012 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biac/1750914 to your computer and use it in GitHub Desktop.
Save biac/1750914 to your computer and use it in GitHub Desktop.
C# の || と |
static void Main(string[] args) {
if (expr1() || expr2())
Console.WriteLine("|| - short circuit");
if (expr1() | expr2())
Console.WriteLine("| - both evaluated");
Console.ReadKey();
}
private static bool expr1() {
Console.WriteLine("expr1: true");
return true;
}
private static bool expr2() {
Console.WriteLine("expr2: true");
return true;
}
//出力:
//expr1: true
//|| - short circuit
//expr1: true
//expr2: true
//| - both evaluated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment