CKTIS / C#
else: referência prática
else: referência prática: else escolhe o ramo quando a condição if associada vale false.
Versão: C# language; verified against C# 14 reference
Sintaxe
else /* grammar-specific form */else escolhe o ramo quando a condição if associada vale false.
Usa-o para uma alternativa exclusiva, mantendo ambos os ramos curtos.
else associa-se ao if sem par mais próximo; as chavetas eliminam a ambiguidade.
Sem else o fluxo continua, e else if é um if aninhado.
O programa completo usa realmente else; o stdout exato esperado é low.
Exemplos
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
var value = 3; if (value > 5) Console.WriteLine("high"); else Console.WriteLine("low");
Resultado
low
O programa completo usa realmente `else`; o stdout exato esperado é `low`.