ArrayList and Struct

C

Ching-Lung

Hi,

The code:

class Row
{
public int m_Id;
public string m_Name;

public Row(int id, string name)
{
m_Id = id;
m_Name = name;
}
}

class Table
{
public ArrayList m_Table;

public Table()
{
Row row1 = new Row(5, "hello");
Row row2 = new Row(10, "world");

m_Table = new ArrayList(2);
m_Table.Add(row);
m_Table.Add(row2);
}

public int GetId(int rowNumber)
{
return m_Table[rowNumber].???
}

public string GetName(int rowNumber)
{
return m_Table[rowNumber].???
}
}

If I call Table.GetId(0), it should return 5. If I call
Table.GetName(1), it should return "world".

So, how do I access the public members of class Row from
the ArrayList in class Table?

Please help. Thanks!
-CL
 
A

Alex Ting

Hi...

Try this

((Row)m_Table[rowNumber]).Row;
cast it as a Row and use properties:

Ching-Lung said:
Hi,

The code:

class Row
{
public int m_Id;
public int M_Id
{
get
{
return m_Id;
}
set
{
m_Id = value;
}
}
public string m_Name;

public Row(int id, string name)
{
m_Id = id;
m_Name = name;
}
}

class Table
{
public ArrayList m_Table;

public Table()
{
Row row1 = new Row(5, "hello");
Row row2 = new Row(10, "world");

m_Table = new ArrayList(2);
m_Table.Add(row);
m_Table.Add(row2);
}

public int GetId(int rowNumber)
{
return m_Table[rowNumber].???
}

public string GetName(int rowNumber)
{
return m_Table[rowNumber].???
}
}

If I call Table.GetId(0), it should return 5. If I call
Table.GetName(1), it should return "world".

So, how do I access the public members of class Row from
the ArrayList in class Table?

Please help. Thanks!
-CL
 
C

Ching-Lung

Thank you!

-----Original Message-----
Hi...

Try this

((Row)m_Table[rowNumber]).Row;
cast it as a Row and use properties:

Ching-Lung said:
Hi,

The code:

class Row
{
public int m_Id;
public int M_Id
{
get
{
return m_Id;
}
set
{
m_Id = value;
}
}
public string m_Name;

public Row(int id, string name)
{
m_Id = id;
m_Name = name;
}
}

class Table
{
public ArrayList m_Table;

public Table()
{
Row row1 = new Row(5, "hello");
Row row2 = new Row(10, "world");

m_Table = new ArrayList(2);
m_Table.Add(row);
m_Table.Add(row2);
}

public int GetId(int rowNumber)
{
return m_Table[rowNumber].???
}

public string GetName(int rowNumber)
{
return m_Table[rowNumber].???
}
}

If I call Table.GetId(0), it should return 5. If I call
Table.GetName(1), it should return "world".

So, how do I access the public members of class Row from
the ArrayList in class Table?

Please help. Thanks!
-CL


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.536 / Virus Database: 331 - Release Date: 3/11/2003


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top