Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

and: practical reference

and: practical reference: and combines logical patterns and matches when both patterns are satisfied.

Version: C# language and .NET 10 reference runtime

Syntax

and /* grammar-specific form */

and combines logical patterns and matches when both patterns are satisfied.

Use it in is or switch for readable range and type constraints.

Pattern precedence differs from Boolean operators; use parentheses to state intent.

The second pattern can use the type narrowed by the first.

The complete program actually uses and; its exact expected stdout is True.

Examples

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);

Result

True

The complete program actually uses `and`; its exact expected stdout is `True`.

Sources