CKTIS / C#
extern: referencia práctica
extern: referencia práctica: extern declara una implementación fuera del código C# o un alias de referencia externa.
Versión: C# language; verified against C# 14 reference
Sintaxis
extern /* grammar-specific form */extern declara una implementación fuera del código C# o un alias de referencia externa.
Usa extern con DllImport cuando el runtime crea el stub P/Invoke; el P/Invoke source-generated usa LibraryImport en un método static partial, no extern.
Una firma nativa errónea puede corromper el proceso en vez de limitarse a lanzar una excepción.
La biblioteca o el símbolo puede faltar en una plataforma; marshaling requiere tipos explícitos.
El programa completo usa realmente extern; 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;
Console.WriteLine(Native.GetProcessId() > 0);
static partial class Native { [DllImport("libc", EntryPoint = "getpid")] public static extern int GetProcessId(); }
Resultado
True
El programa completo usa realmente `extern`; su stdout esperado exacto es `True`.