Repository navigation
RU CSharp Keyword extern
Codex edited this page Oct 11, 2026
·
2 revisions
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Справочник C# · Практическое руководство
Объявляет член, реализуемый вне C#-кода; типично для native interop через DllImport. extern alias задает внешний assembly-псевдоним.
Сохраните этот пример отдельно как Example.cs. Запускайте его независимо от остальных примеров страницы.
Example.cs:
// PROJECT-EXAMPLE
class NativeMethods
{
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
public static extern uint GetCurrentProcessId();
}Только объявление: код компилируется как библиотека; для запуска нужен вызов из Main.
[DllImport(...)] public static extern ReturnType Method(...);Эти два native примера предназначены для Windows. Название библиотеки, ABI и доступность функции зависят от платформы; компиляция сама не проверяет их наличие.
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(); }Официальный источник: Microsoft Learn.
ClassicUO — Bad Newbie & C# Scripts IDE