Skip to content

RU CSharp Directive Pragma

Codex edited this page Oct 11, 2026 · 2 revisions

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

Управление диагностикой

Справочник C# · Практическое руководство

warning disable/restore изменяет выбранные предупреждения. checksum задает контрольную сумму для отладочной информации сгенерированного источника.

Простой пример (Example.cs)

Сохраните этот пример отдельно как Example.cs. Запускайте его независимо от остальных примеров страницы.

Example.cs:

// PROJECT-EXAMPLE
#pragma warning disable CS0168
int unused;
#pragma warning restore CS0168
System.Console.WriteLine("Ready");

Результат:

Ready

Синтаксис

#pragma warning disable CODE / restore CODE

Приклад 1

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)
    {
        #pragma warning disable CS0168
        int unused;
        #pragma warning restore CS0168
        Console.WriteLine("Ready");
    }
}

Приклад 2

#pragma checksum "Generated.cs" "{8829d00f-11b8-4213-878b-770e8597ac16}" "00112233445566778899AABBCCDDEEFF"
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("Source mapped");
    }
}

Официальный источник: Microsoft Learn.

Clone this wiki locally