参考ページ
スクリプトでのインストール
インストール方法
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