I am trying to get a list from another form. I have made the list public and put it in its own class to no avail.
Form1:
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;
using System.Data.Common;
using System.Configuration;
namespace eAnfonebu
{
public class variables
{
public List<int> rhifAnfoneb = new List<int>();
public List<int> rhifArcheb = new List<int>();
public string[] ddydiadArcheb;
public string[] enwArchebwr;
public string[] eBost;
public int[] gair;
public decimal[] prisMilGair;
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void createNew_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.ShowDialog(); // Shows Form2
}
}
}
Form2 (addInvoice):
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 eAnfonebu
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void AddInvoice_Click(object sender, EventArgs e)
{
try
{
variables.rhifAnfoneb.Add(variables.rhifAnfoneb[variables.rhifAnfoneb.Length - 1] + 1);
}
catch
{
variables.rhifAnfoneb.Add(1);
}
}
}
}
I am getting the error (An object reference is required for the non-static field, method, or property 'variables.rhifAnfoneb') in
try
{
variables.rhifAnfoneb.Add(variables.rhifAnfoneb[variables.rhifAnfoneb.Length - 1] + 1);
}
catch
{
variables.rhifAnfoneb.Add(1);
}
I am sorry for different languages in same code but I am billingual and sometimes I set out to make an app in one language but then it slowly morphs to another.
If awnsering could you please awnser as simply as you could because I am new to c#
Any help would be greatly appreciated.
Eoin