「C#」Addでリストlistに要素を追加する
書式
リスト名.Add(要素)
使用例
using System;
using System.Collections.Generic;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var intLst = new List<int> { 11, 23, 45 };
var strLst = new List<string> { "study", "skill" };
//リストに値を追加
intLst.Add(67);
intLst.Add(89);
strLst.Add("arkgame");
// foreachでint型リストの要素を出力
foreach (int i in intLst)
{
Console.Write("{0} ", i);
}
Console.WriteLine();
// foreachでstrin型リストの要素を出力
foreach (string m in strLst)
{
Console.Write("{0} ", m);
}
}
}
}
結果
11 23 45 67 89
study skill arkgame