C#オンラインコンパイラ&デバッガー

C#コードをオンラインで作成、コンパイル、実行、デバッグできます。Visual Studioなしで、複数ファイルIDEのブレークポイント、ステップ実行、オブジェクト確認を利用できます。

🚀 349,461 合計実行 (43,719 今月)
出力

C#のコーディングチャレンジで練習

このエディタで実践的な問題を解こう。サンプルテストを実行し、提出してAIコードレビューを受けられます。

すべてのC#チャレンジ
難しい

Course Schedule Order

Order courses so every prerequisite comes first.

AdvancedGraphsHackathonTopological-sort
まだ解答がありません
中級

Island Perimeter

Measure the coastline of land cells in a grid.

AdvancedGridsHackathon
まだ解答がありません
中級

K-th Smallest Element

Find the k-th smallest value without fully sorting.

AdvancedCompetitive-programmingSorting
まだ解答がありません
難しい

2つのソート済み配列の中央値

2つのソート済みリストを結合したときの中央値を求めてください。

AdvancedBinary-searchCompetitive-programming
まだ解答がありません
中級

Game of Life Step

Advance Conway's Game of Life by one generation.

AdvancedGridsHackathonSimulation
まだ解答がありません
難しい

Shortest Delivery Tour

Visit every city once and return home as cheaply as possible.

AdvancedBitmasksCompetitive-programmingDynamic-programming
まだ解答がありません
難しい

Strongly Connected Components

Count groups of nodes that can all reach each other.

AdvancedCompetitive-programmingGraphs
まだ解答がありません
難しい

Longest Path in a DAG

Find the heaviest path in a task dependency graph.

AdvancedGraphsHackathonTopological-sort
まだ解答がありません
難しい

Matrix Chain Multiplication

Find the cheapest order to multiply a chain of matrices.

AdvancedCompetitive-programmingDynamic-programming
まだ解答がありません
難しい

Minimum Window Substring

Find the shortest piece of text containing all required characters.

AdvancedCompetitive-programmingSliding-windowStrings
まだ解答がありません
難しい

Word Break

Decide whether text can be split into dictionary words.

AdvancedDynamic-programmingHackathonStrings
まだ解答がありません
難しい

Count Inversions

Count the out-of-order pairs in a list.

AdvancedCompetitive-programmingSorting
まだ解答がありません

🔷 この C# / .NET オンライン実行ツールについて

CodeUtility C# Executor は、ブラウザ上で本物の C# コードをそのまま書いて実行できるツールです — インストール、Visual Studio のセットアップ、.NET SDK は不要です。安全なサンドボックスで動作し、 .NET ランタイムと C# 9 以降を含むモダンな C# 言語バージョンに対応しています。

このツールは内部で dotnet-script を用いてコードをコンパイル・実行し、.NET 本来の挙動で動かせます。 LINQ、async/await、パターンマッチ、ジェネリクスといった基本から高度な C# 機能まで試せます。

シンプルなスクリプト、関数、ロジックの流れを検証したり、クラス、構造体、継承、インターフェイスなどの概念を — 余計なもののない快適なコーディング環境で探索できます。

C# を学習中でも、アルゴリズムを検証中でも、.NET の機能を実験中でも、CodeUtility C# Executor なら、どのブラウザからでも C# コードをすぐに安全・確実に実行できます。

単なるコードランナーではありません

同じ実行環境で、複数ファイル対応エディター、分離された実行ターミナル、ランタイム別ライブラリ、永続ワークスペース、共有、リアルタイム共同作業を利用できます。

この実行環境の使い方

ランタイムを選択し、ファイルを開くか作成してコードを記述し、[実行]を選択します。出力はターミナルに表示されます。サインインしたユーザーは、ワークスペースにファイルを保存し、ライブラリをインストールして、共有を通じて共同作業できます。

  1. バージョンを選択して現在のファイルを編集するか、ワークスペース内の別のファイルを開きます。
  2. コードを実行し、求められた場合はターミナルに入力して、保存された実行履歴を確認します。
  3. 複数のコードスニペットが必要な作業では、ライブラリ、ワークスペースツール、共有、チャットを利用します。

💡 C# の基本と、上で試せるサンプル

1. 変数と定数の宣言

C# では強い型付けの変数宣言を使います。コンパイル時の定数には const、実行時に決まる定数には readonly を使います。

int age = 30;
double pi = 3.14159;
char grade = 'A';
string name = "Alice";
bool isActive = true;

// 定数
const int MaxUsers = 100;
const string Company = "CodeUtility";

2. 条件分岐 (if / switch)

制御フローには if、else if、switch を使います。

int x = 2;
if (x == 1)
{
    Console.WriteLine("1");
}
else if (x == 2)
{
    Console.WriteLine("2");
}
else
{
    Console.WriteLine("その他");
}

switch (x)
{
    case 1:
        Console.WriteLine("1");
        break;
    case 2:
        Console.WriteLine("2");
        break;
    default:
        Console.WriteLine("その他");
        break;
}

3. ループ

C# は for、while、foreach ループをサポートします。

for (int i = 0; i < 3; i++)
{
    Console.WriteLine(i);
}

int n = 3;
while (n > 0)
{
    Console.WriteLine(n);
    n--;
}

4. 配列

配列は同じ型の要素を固定長で格納します。

int[] numbers = { 10, 20, 30 };
Console.WriteLine(numbers[1]);

5. リストの操作

動的なコレクションには List<T> を使います。

List<int> nums = new List<int> { 1, 2, 3 };
nums.Add(4);
nums.Remove(2);

foreach (int n in nums)
{
    Console.Write(n + " ");
}

6. コンソール入出力

基本的な入出力には Console.WriteLine と Console.ReadLine を使用します。

Console.Write("あなたの名前を入力してください: ");
string name = Console.ReadLine();
Console.WriteLine($"こんにちは、{name}!");

7. 関数

戻り値の型、名前、引数を指定してメソッドを定義します。

int Add(int a, int b)
{
    return a + b;
}

Console.WriteLine(Add(3, 4));

8. ディクショナリ

Dictionary<TKey, TValue> はキーと値のペアを保持します。

Dictionary<string, int> ages = new Dictionary<string, int>();
ages["Alice"] = 30;
Console.WriteLine(ages["Alice"]);

9. 例外処理

実行時エラーは try、catch、finally で扱います。

try
{
    throw new Exception("問題が発生しました");
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}

10. ファイル I/O

ファイル操作には File と StreamReader/StreamWriter を使います。

File.WriteAllText("file.txt", "Hello File");
string text = File.ReadAllText("file.txt");
Console.WriteLine(text);

11. 文字列操作

C# の文字列は Length、Substring、Contains などのメソッドを利用できます。

string message = "Hello World";
Console.WriteLine(message.Length);
Console.WriteLine(message.Substring(0, 5));
Console.WriteLine(message.Contains("World"));

12. クラスとオブジェクト

C# はクラスとオブジェクトによるオブジェクト指向をサポートします。

class Person
{
    public string Name;
    public Person(string name) => Name = name;
    public void Greet() => Console.WriteLine($"こんにちは、{Name}です");
}

Person p = new Person("Alice");
p.Greet();