Repository navigation
FR CSharp Keyword extern
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Déclare un membre implémenté en dehors du code C# ; typique pour l'interopérabilité native via DllImport. extern alias spécifie un alias d’assembly externe.
Enregistrez cet exemple séparément dans Example.cs. Exécutez-le indépendamment des autres exemples de cette page.
Example.cs:
// PROJECT-EXAMPLE
class NativeMethods
{
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
public static extern uint GetCurrentProcessId();
}Déclaration uniquement : ce code se compile comme bibliothèque ; appelez-le depuis Main pour l’exécuter.
[DllImport(...)] public static extern ReturnType Method(...);Ces deux exemples natifs sont pour Windows. Le nom de la bibliothèque, ABI et la disponibilité des fonctionnalités dépendent de la plate-forme ; la compilation elle-même ne vérifie pas leur présence.
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(); }Source officielle : Microsoft Apprendre.
ClassicUO — Bad Newbie & C# Scripts IDE