.NET Core
Вызов функции в зависимости от операционной системы:
C# | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| using System.Runtime.InteropServices;
[DllImport("msvcrt.dll",EntryPoint = "system",CallingConvention = CallingConvention.Cdecl, SetLastError=true)]
static extern int WinSystem(string command);
[DllImport("libc.so.6",EntryPoint = "system",SetLastError = true)]
static extern int LinSystem(string command);
static void Main(string[] args)
{
// console clear
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
WinSystem("cls");
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
LinSystem("clear");
else
throw new NotSupportedException();
} |
|
|