CKTIS / C#
unmanaged: praktická reference
unmanaged: praktická reference: Omezení unmanaged připouští hodnotové typy bez spravovaných referencí; slovo popisuje i ABI ukazatele na funkci.
Verze: C# language; verified against C# 14 reference
Syntaxe
unmanaged /* grammar-specific form */Omezení unmanaged připouští hodnotové typy bez spravovaných referencí; slovo popisuje i ABI ukazatele na funkci.
Použijte jej v generickém binárním kódu a interopu vyžadujícím reprezentaci bez referencí.
unmanaged bez StructLayout nezaručuje shodný layout mezi platformami.
Nullable a typy s referencemi omezení nesplní; velikost závisí na architektuře.
Úplný program skutečně používá unmanaged; přesně očekávaný stdout je 4.
Pří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;
Console.WriteLine(Size<int>()); static int Size<T>() where T : unmanaged => Unsafe.SizeOf<T>();
Výsledek
4
Úplný program skutečně používá `unmanaged`; přesně očekávaný stdout je `4`.