「C#」配列を作成する方法
書式
データ型[]配列名 = new データ型「要素数」
int[] cftLst = new int[3];
String[] strLst = new String[3];
使用例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//int型配列の定義
int[] cftLst = new int[3];
cftLst[0] = 111;
cftLst[1] = 222;
cftLst[2] = 333;
Console.WriteLine("int型配列の要素");
for (int i = 0; i < cftLst.Length; i++)
{
Console.WriteLine(cftLst[i]);
}
//String型配列の定義
String[] strLst = new String[3];
strLst[0] = "study";
strLst[1] = "skill";
strLst[2] = "in arkgame";
Console.WriteLine("String型配列の要素");
for (int i = 0; i < strLst.Length; i++)
{
Console.WriteLine(strLst[i]);
}
Console.ReadKey();
}
}
}
実行結果
int型配列の要素
111
222
333
String型配列の要素
study
skill
in arkgame