0 1 2 3 4 5 6 7 8 9 ------------------------ 9 8 7 6 5 4 3 2 1 0 |
前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
//★ ArrayListの基礎 前田 稔 ★
using System;
using System.Collections;
class Prog
{
public static void Main()
{
ArrayList array;
int i;
array = new ArrayList();
for(i=0; i<10; i++) array.Add(i);
foreach (int DAT in array)
{
Console.Write("{0} ", DAT);
}
Console.WriteLine("\n------------------------");
for (i=0; i<array.Count; i++)
{
Console.Write("{0} ", array[i]);
}
}
}
|
| using System.Collections; |
| ArrayList array; |
| array = new ArrayList(); |
int i;
array.Add(i);
|
foreach (int DAT in array)
{
Console.Write("{0} ", DAT);
}
|
for (i=0; i<array.Count; i++)
{
Console.Write("{0} ", array[i]);
}
|
| for (i = array.Count-1; i >= 0; i--) |
| array.Reverse(); |
ArrayList ary= new ArrayList(new short[] { 3, 6, 1, 5, 8, 0, 9, 7, 4, 2 });
foreach (short DAT in ary)
{
Console.Write("{0} ", DAT);
}
|
using System.Collections;
public class Hello
{ public static void Main()
{ // 初期化
var myarray = new ArrayList(){ "red", "green", "blue", "yellow", "black", "white" };
// 要素の表示
System.Console.WriteLine(string.Join(",",(string[])myarray.ToArray(typeof(string))));
// 要素のソート(昇順)
myarray.Sort();
// 要素の表示
System.Console.WriteLine(string.Join(",",(string[])myarray.ToArray(typeof(string))));
// 要素のソート(降順)
myarray.Reverse();
// 要素の表示
System.Console.WriteLine(string.Join(",",(string[])myarray.ToArray(typeof(string))));
}
}
|
![]()
| array.Add(dat); |
|
for (i = 0; i<array.Count; i++) |
| array.RemoveAt(index); |
| array.Insert(index, dat); |
| array.Clear(); |
![]()