0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

dotnet の使い方

Last updated at Posted at 2023-04-30

参考ページ
スクリプトでのインストール

インストール方法

Ubuntu 23.04 にインストールしました。

wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
chmod +x ./dotnet-install.sh
sudo ./dotnet-install.sh -i /usr/local/bin

確認したバージョン

$ dotnet --version
6.0.408

プロジェクトの作成

mkdir sample
cd sample
dotnet new console --use-program-main

次のファイルが作成されます。

$ tree 
.
├── Program.cs
├── obj
│   ├── project.assets.json
│   ├── project.nuget.cache
│   ├── sample.csproj.nuget.dgspec.json
│   ├── sample.csproj.nuget.g.props
│   └── sample.csproj.nuget.g.targets
└── sample.csproj

2 directories, 7 files

Program.cs を編集

Program.cs
namespace sample;
class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello, World!");
        Console.WriteLine("こんにちは!");
        Console.WriteLine("Apr/30/2023");
    }
}

プログラムの実行

$ dotnet run
Hello, World!
こんにちは!
Apr/30/2023

一度、dotnet run を実行すれば、次のようにしても実行が出来ます。

$ dotnet bin/Debug/net6.0/sample.dll
Hello, World!
こんにちは!
Apr/30/2023

プログラムの改造

もう少し、プログラムを複雑にしてみます。

Program.cs
namespace sample;
class Program
{
	static void Main(string[] args)
	{
	Console.WriteLine("こんにちは!");
	for (int it=0; it<5; it++)
		{
		Console.WriteLine("it = " + it);
		}
	Console.WriteLine("Apr/30/2023");
	}
}

実行結果

$ dotnet run
こんにちは!
it = 0
it = 1
it = 2
it = 3
it = 4
Apr/30/2023
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?