Skip to content

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