Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / C#

and: referencia práctica

and: referencia práctica: and combina patrones lógicos y coincide cuando se cumplen ambos.

Versión: C# language and .NET 10 reference runtime

Sintaxis

and /* grammar-specific form */

and combina patrones lógicos y coincide cuando se cumplen ambos.

Úsalo en is o switch para restricciones legibles de intervalo y tipo.

La precedencia de patrones difiere de los operadores booleanos; usa paréntesis.

El segundo patrón puede usar el tipo restringido por el primero.

El programa completo usa realmente and; su stdout esperado exacto es True.

Ejemplos

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;

object value = 7; Console.WriteLine(value is > 0 and < 10);

Resultado

True

El programa completo usa realmente `and`; su stdout esperado exacto es `True`.

Fuentes