Repository navigation
DE CSharp Keyword extern
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Handbuch C# · Praktischer Leitfaden
Deklariert ein Mitglied, das außerhalb des C#-Codes implementiert ist; typisch für natives Interop über DllImport. Externer Alias gibt einen externen Assembly-Alias an.
Speichern Sie dieses Beispiel separat als Example.cs. Führen Sie es unabhängig von den anderen Beispielen dieser Seite aus.
Example.cs:
// PROJECT-EXAMPLE
class NativeMethods
{
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
public static extern uint GetCurrentProcessId();
}Nur eine Deklaration: Der Code wird als Bibliothek kompiliert; zum Ausführen ist ein Aufruf aus Main erforderlich.
[DllImport(...)] public static extern ReturnType Method(...);Diese beiden nativen Beispiele gelten für Windows. Bibliotheksname, ABI und Funktionsverfügbarkeit sind plattformabhängig; Die Kompilierung selbst prüft nicht, ob sie vorhanden sind.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public static class Program
{
public static async Task Main(string[] args)
{
Console.WriteLine(Native.GetCurrentProcessId());
}
}
public static class Native { [DllImport("kernel32.dll")] public static extern uint GetCurrentProcessId(); }using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public static class Program
{
public static async Task Main(string[] args)
{
Console.WriteLine(Native.GetTickCount64());
}
}
public static class Native { [DllImport("kernel32.dll")] public static extern ulong GetTickCount64(); }Offizielle Quelle: Microsoft Learn.
ClassicUO — Bad Newbie & C# Scripts IDE