PC Review


Reply
Thread Tools Rate Thread

ArrayList with structur as element

 
 
Peter
Guest
Posts: n/a
 
      29th Apr 2009
Marin wrote:

> I have a structur in a class level like this
>
> public struct sunData
>
> {
>
> public int location;
>
> public string url_address;
>
> public string mac_address;
>
> }
>
> ..........................
>
> Inside one of the methods in the class I use a LiatArray like this
>
> ArrayList SunsCollection = new ArrayList();
>
> and I assin the following 3 values inside a loop and it works fine.
>
> sunData sundata;
>
> sundata.location = (int)SunsdataRow["LOCATION"];
>
> sundata.url_address = SunsdataRow["IP_ADDRESS"].ToString();
>
> sundata.mac_address = SunsdataRow["MAC_ADDRESS"].ToString();
>
> // add to the ListArray collection
>
> SunsCollection.Add(sundata);
>
> Problem is that I can't print the data from the listarray into a
> consol or a logger like this
>
> Console.WriteLine(SunsCollection[0].url_address );
>
> I get a the following error
>
> Error 80 'object' does not contain a definition for 'location'
>
> Can someone help me please?
>
> Reagrds
>
> Marin


You would need to cast the object you get from the ArrayList to the
type you need. For example:

string address = ((SunData)sunsCollection[0]).UrlAddress;

Or use a List<SunData>.
For example:
using System.Collections.Generic;

List<SunData> sunsList = new List<SunData>();

// add some SunData objects to the list...

string address = sunsList[0].UrlAddress;


/Peter

--

 
Reply With Quote
 
 
 
 
Marin
Guest
Posts: n/a
 
      29th Apr 2009
I have a structur in a class level like this

public struct sunData

{

public int location;

public string url_address;

public string mac_address;

}

...........................

Inside one of the methods in the class I use a LiatArray like this

ArrayList SunsCollection = new ArrayList();

and I assin the following 3 values inside a loop and it works fine.

sunData sundata;

sundata.location = (int)SunsdataRow["LOCATION"];

sundata.url_address = SunsdataRow["IP_ADDRESS"].ToString();

sundata.mac_address = SunsdataRow["MAC_ADDRESS"].ToString();

// add to the ListArray collection

SunsCollection.Add(sundata);

Problem is that I can't print the data from the listarray into a consol or a
logger like this

Console.WriteLine(SunsCollection[0].url_address );

I get a the following error

Error 80 'object' does not contain a definition for 'location'

Can someone help me please?

Reagrds

Marin


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
arraylist - how do I retrieve a single element? Peter Webb Microsoft C# .NET 5 6th Nov 2007 07:47 AM
How to reference the first element in an arraylist garyusenet@myway.com Microsoft C# .NET 10 5th Dec 2006 04:03 PM
Deleting ArrayList element from DataGrid nadeem_far@yahoo.com Microsoft C# .NET 5 18th Nov 2005 01:29 PM
Update Element in ArrayList Structure wg Microsoft VB .NET 8 26th Jun 2005 04:58 PM
How to access an array element in a member of ArrayList? =?Utf-8?B?SGFvYmlu?= Microsoft C# .NET 9 21st May 2004 08:52 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:42 PM.