CKTIS / C#
unmanaged: odniesienie praktyczne
unmanaged: odniesienie praktyczne: unmanaged constraint dopuszcza wartościowe typy bez zarządzanych referencji; keyword opisuje też ABI function pointer.
Wersja: C# language; verified against C# 14 reference
Składnia
unmanaged /* grammar-specific form */unmanaged constraint dopuszcza wartościowe typy bez zarządzanych referencji; keyword opisuje też ABI function pointer.
Stosuj w generic kodzie binarnym i interopie wymagającym typów wartościowych bez zarządzanych referencji; layout trzeba określić osobno.
Unmanaged nie gwarantuje identycznego layoutu między platformami bez StructLayout.
Nullable i typy zawierające referencje nie spełniają constraint; rozmiar zależy od architektury.
Kompletny program rzeczywiście używa unmanaged; oczekiwany stdout to dokładnie 4.
Przykłady
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>();
Wynik
4
Kompletny program rzeczywiście używa `unmanaged`; oczekiwany stdout to dokładnie `4`.