LoginSignup
2
1

C#をコンソールで実行するため最短コマンド

Last updated at Posted at 2024-04-12

最短コマンド

dotnet new console -o MyApp
# cd MyApp
# dotnet add package Newtonsoft.Json
# nvim MyApp/Program.cs
dotnet run

説明

  1. コマンドプロンプト,Powershellまたはターミナルを開き、次のコマンドを実行します:
dotnet new console -o MyApp
cd MyApp
  1. 次に、ライブラリを追加します。(任意)
dotnet add package Newtonsoft.Json
  1. Program.cs ファイルを編集します:(任意)
nvim MyApp/Program.cs
using System;
using System.IO;
using Newtonsoft.Json;

namespace MyApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string filePath = "test.txt";

            // ファイルを開く
            using (StreamReader file = File.OpenText(filePath))
            {
                string content = file.ReadToEnd(); // ファイルの内容を読み取る
                Console.WriteLine(content); // ファイルの内容をコンソールに出力する
            } // ファイルを閉じる
        }
    }
}
  1. 最後に、アプリケーションをビルドして実行します:
dotnet run
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1