Skip to content

CSharp Directive Region

Codex edited this page Oct 11, 2026 · 2 revisions

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

Згортання коду

Довідник C# · Практичне керівництво

Позначає ділянки, які редактор може згорнути. Не створює нову область видимості та не впливає на runtime-поведінку.

Простий приклад (Example.cs)

Збережіть цей приклад окремо як Example.cs. Запускайте його незалежно від інших прикладів на сторінці.

Example.cs:

// PROJECT-EXAMPLE
#region Report
int count = 3;
System.Console.WriteLine(count);
#endregion

Результат:

3

Синтаксис

#region Name / #endregion

Приклад 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)
    {
        #region Report
        int count = 3;
        Console.WriteLine(count);
        #endregion
    }
}

Приклад 2

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(Reports.Format(5));
    }
}
public static class Reports {
#region Formatting
public static string Format(int count) => "Count=" + count;
#endregion
}

Офіційне джерело: Microsoft Learn.

Clone this wiki locally