using System;
// Listを使う際には以下を宣言する
using System.Linq;
using System.Collections.Generic;
namespace weightsRemove
{
class MainClass
{
public static void Main(string[] args)
{
// 1週間分の体重で3日目の体重データを削除してから表示する例
// 1. List型の変数を作る
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. Listの先頭から3番目を削除する
weights.RemoveAt(2);
// List<T>.Count -> List<T> に格納されている要素の数を取得
for (int i = 0; i < weights.Count; i++)
{
Console.WriteLine(weights[i]);
// weights.Add(71.2f);が消えている!
}
}
}
}
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
0