Skip to content

CSharp Keyword args

Codex edited this page Oct 11, 2026 · 2 revisions

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

C#: args

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

Неявний string[] параметр верхньорівневої програми. У звичайному Main таке ім’я параметра є домовленістю, а не обов’язковим словом.

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

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

Example.cs:

// PROJECT-EXAMPLE
System.Console.WriteLine(args.Length == 0 ? "No arguments" : args[0]);

Результат:

No arguments

Синтаксис

string[] args / top-level args

Приклад 1: базова форма

using System; Console.WriteLine(args.Length > 0 ? args[0] : "No arguments");

Приклад 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)
    {
        for (int i = 0; i < args.Length; i++) Console.WriteLine($"{i}:{args[i]}");
    }
}

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

Clone this wiki locally