I was following this video: http://www.youtube.com/watch?v=Y63vq_tcTGk and at 8:20 he types
ds.Add(a);
show_diem();
however an error comes up when I do ds.Add(a);
I'm new to this so I'm still unsure of what ds is? Can it be anything? He declares
ds = new ArrayList();
at the beginning so can it be anything? And why is the error popping up? Here is the code on my Form1. "Employee" is a class and "employeeId" "firstName" etc are textboxes. I used "em" instead of "ds".
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;
using System.Collections;
namespace Employee_Program
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public ArrayList em;
private void Form1_Load(object sender, EventArgs e)
{
em = new ArrayList();
}
private void show_employee()
{
listView1.Items.Clear();
foreach(Employee a in em)
{
int i = listView1.Items.Count;
listView1.Items.Add(a.FirstName);
listView1.Items[i].SubItems.Add(a.LastName);
listView1.Items[i].SubItems.Add(a.EmployeeId.ToString());
listView1.Items[i].SubItems.Add(a.YearSalary.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
Employee a = new Employee();
a.FirstName = firstName.Text;
a.LastName = lastName.Text;
a.EmployeeId = float.Parse(employeeId.Text);
a.YearSalary = float.Parse(yearSalary.Text);
em.Add(a);
show_employee();
}
}
}
the error says: Object reference not set to an instance of an object.