using System;
// Listを使う際には以下を宣言する
using System.Linq;
using System.Collections.Generic;
namespace array_sample
{
class MainClass
{
public static void Main(string[] args)
{
//Listは簡単に並び替えができる
//リスト名.Sort();で並び替えができる
// 1週間分の体重データで軽い順にベスト3を表示する例
// 1. List型の変数を作る
//ここでは、リスト名:weights
List<float> weights = new List<float>();
// 2. Listに要素を追加する
weights.Add(61.2f);
weights.Add(51.2f);
weights.Add(71.2f);
weights.Add(54.2f);
weights.Add(68.2f);
weights.Add(61.3f);
weights.Add(68.1f);
weights.Add(64.3f);
weights.Add(65.4f);
// 例:weights[1] = 61.2f
// 3. 小さい順に並び替える
weights.Sort();
// 4. for文で回す
for (int i = 0; i < 3; i++)
{
Console.WriteLine(weights[i]);
}
}
}
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
List of users who liked
00