Znalostná bázaCentrum skúšok
SKSlovenčina
Vybrať jazyk13

CKTIS / C#

into: praktická referencia

into: praktická referencia: into po klauzule group, join alebo select naviaže nový medzivýsledkový identifikátor, aby mohla query pokračovať.

Verzia: C# language; verified against C# 14 reference

Syntax

into /* grammar-specific form */

into po klauzule group, join alebo select naviaže nový medzivýsledkový identifikátor, aby mohla query pokračovať.

Použite na ďalšie filtrovanie alebo projekciu skupiny.

Predchádzajúce rozsahové premenné mimo zachovaných údajov už nie sú dostupné.

Prázdna skupina po group join stále existuje; význam určuje predchádzajúca klauzula.

Úplný program skutočne používa into; presne očakávaný stdout je 1:6:A;3:4:C.

Príklady

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 left = new[] { (Id: 1, Value: 3), (Id: 2, Value: 1), (Id: 3, Value: 2) };
var right = new[] { (Id: 1, Name: "A"), (Id: 3, Name: "C") };
var query = from item in left
            join label in right on item.Id equals label.Id into labels
            from label in labels.DefaultIfEmpty()
            let doubled = item.Value * 2
            where doubled > 2
            orderby item.Value descending, item.Id ascending
            select new { item.Id, doubled, Name = label.Name ?? "-" };
Console.WriteLine(string.Join(";", query.Select(row => $"{row.Id}:{row.doubled}:{row.Name}")));

Výsledok

1:6:A;3:4:C

Úplný program skutočne používa `into`; presne očakávaný stdout je `1:6:A;3:4:C`.

Zdroje