Skip to content

JA 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