逆の処理であるList<T>から配列に変換する場合のコードはこちらの記事を参照してください。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ArrayListConvert
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
int[] array = new int[5];
array[0] = 2;
array[1] = 8;
array[2] = 34;
array[3] = 12;
array[4] = 6;
List<int> vlist = new List<int>(array);
for (int i = 0; i < vlist.Count; i++) {
textBox1.Text += vlist[i] + "\r\n";
}
}
}
}
int[] array = new int[5];
array[0] = 2;
array[1] = 8;
array[2] = 34;
array[3] = 12;
array[4] = 6;
配列のインデックス | 0 | 1 | 2 | 3 | 4 |
値 | 2 | 8 | 34 | 12 | 6 |
List<int> vlist = new List<int>(array);
for (int i = 0; i < vlist.Count; i++) {
textBox1.Text += vlist[i] + "\r\n";
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ArrayListConvert
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
private void button4_Click(object sender, EventArgs e)
{
string[] array = new string[5];
array[0] = "Duck";
array[1] = "Chiken";
array[2] = "Hawk";
array[3] = "Lion";
array[4] = "Panda";
List<string> vlist = new List<string>(array);
for (int i = 0; i < vlist.Count; i++) {
textBox1.Text += vlist[i] + "\r\n";
}
}
}
}
string[] array = new string[5];
array[0] = "Duck";
array[1] = "Chiken";
array[2] = "Hawk";
array[3] = "Lion";
array[4] = "Panda";
for (int i = 0; i < vlist.Count; i++) { textBox1.Text += vlist[i] + "\r\n"; }