using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace project1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
label2.Text = " ";
Random r = new Random();
int num;
int[] myarray = new int[5];
for (int i = 0; i < 10; i++)
{
num = r.Next(1, 6);
label2.Text = label2.Text+num.ToString()+" ";
myarray[num - 1]++; //บรรทัดนี้อะค่ะอยากทราบว่ามันทำงานยังไงแล้วทำไมต้องมี -1 ด้วยคะ
}
for (int i = 0; i < myarray.Length; i++)
listBox1.Items.Add("Number " + (i + 1).ToString()
+ " = " + myarray[i].ToString());
}
}
}