473,385 Members | 1,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ArrayList and Struct

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
Nov 15 '05 #1
2 4180
Hi...

Try this

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

"Ching-Lung" <cl******@hotmail.com> wrote in message
news:00****************************@phx.gbl...
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
Nov 15 '05 #2
Thank you!

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

Try this

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

"Ching-Lung" <cl******@hotmail.com> wrote in message
news:00****************************@phx.gbl...
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

.

Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Michael C | last post by:
Is it possible to use an ArrayList inside a struct? I keep running into a null reference exception when I try to Add to the ArrayList in the struct, and it won't let me initialize the ArrayList in...
1
by: Irfan Akram | last post by:
Dear Friends, I'll be glad if you guys could help out. I am currently doing a web project in asp.net using c#. An ArrayList object in my code contains element records containing 3 fields. In a...
1
by: Peter Schmitz | last post by:
Hi, I've got the following problem: I need to create a special Dll that is based on MFC, but also includes also managed code (which works fine and isn't a problem). The problem occurrs in the...
8
by: Maileen | last post by:
Hi, I would like to have something like an array (something like a collection) in order to store the following things : company name1, new1, old1, in1, out1 company name2, new2, old2, in2,...
3
by: Frank H. | last post by:
Hi, in my webservice I have a Webmethod wich returns a list of Objects to my C++ Application. C# code: public class Contact { public string FirstName;
31
by: Extremest | last post by:
I have a loop that is set to run as long as the arraylist is > 0. at the beginning of this loop I grab the first object and then remove it. I then go into another loop that checks to see if there...
3
by: pengbsam | last post by:
Hello All: Having a problem with arraylist.copyto function. And here's a sample of my code in C#: In global--> public struct point { int x; string y; }
2
by: pengbsam | last post by:
Hello All: Having a problem with arraylist.copyto function. And here's a sample of my code: In global--> public struct point { int x; string y; } static public point point;
3
by: Christopher H | last post by:
I've been reading about how C# passes ArrayLists as reference and Structs as value, but I still can't get my program to work like I want it to. Simple example: ...
4
by: bbg9507 | last post by:
Hi, question about using ArrayList from C# newbie, I managed to make my array list which holds a number of structs: struct myStruct { public int field1; public int field2; }
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.