Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read data from an array in another class

Tags:

c#

I need to read data from an array located in another class. I have already read a few threads explaining the same problem, but can't get it to work with my code...

Included example: I need to read the data in the ParticipantX array from Parsedata class to the Form1 class, as shown in my example.

I would be really grateful for any help. Best off all would be if you could help me with the code I need. I just got stuck now. Thanks.

public class Parsedata
{
    public void ParsedataMethod()
    {
    ...
        //Neccesary data are added to this array
        string[,] ParticipantX = new string[40, 4];

In the same namespace I have the Form1 class:

using Crestron.ActiveCNX;
public partial class Form1 : Form
{
    ActiveCNX cnx;
    cnx = new ActiveCNX();

    private void SerialSend_Click(object sender, EventArgs e)
    {
        int number = 8;
        for (int i = 1; i < number; i++)
            cnx.SendSerial(i, ParticipantX[i, 1]); //
    }
like image 334
Erik Nordgaard Avatar asked Apr 22 '26 21:04

Erik Nordgaard


1 Answers

Try this:

public class Parsedata
{
     private string[,] m_ParticipantX;
     public void ParsedataMethod()
     {
       ...
       m_ParticipantX = new string[40, 4];//Neccesary data are added to this array
     }

     public string[,] ParticipantX
     {
          get { return m_ParticipantX; }
     }
}

using Crestron.ActiveCNX;
public partial class Form1 : Form
{
    ActiveCNX cnx;
    cnx = new ActiveCNX();
    Parsedata data = new Parsedata();

    private void SerialSend_Click(object sender, EventArgs e)
    {
        data.ParseDataMethod();
        int number = 8;
        for (int i = 1; i < number; i++)
            cnx.SendSerial(i, data.ParticipantX[i, 1]); //
    }
}
like image 119
Azhar Khorasany Avatar answered Apr 24 '26 10:04

Azhar Khorasany