ArrayList

G

Guest

Hi
I have a problem with the ArrayList and the property access. i.e.

Public Class RSSChannel
{
private string _title
private ArrayList _rssitems

public string Title
{
get { return _title; }
set { _title = value; }
}

public ArrayList RSSItems
{
get { return _rssitems;}
set { _rssitems =value; }
}
etc.....
}

I then try and add a RSSitem to the array list like so:

rsschannel.RSSItems.Add(rssitem);

But looking at the debug output it calls the get accessor; I'am clearly doing
something wrong here as I what to call set (and add the RSSitem to the
ArrayList)

What am I doing wrong.

Many thanks
DH
 
E

evidica

public ArrayList RSSItems
{
get { return _rssitems;}
set { _rssitems =value; }
}


You are trying to set an ArrayList equal to a string here. You need to
add it to the list, not reassign it. Try _rssitems.Add(value); instead
of _rssitems = value;
 
J

Jon Skeet [C# MVP]

DH said:
I have a problem with the ArrayList and the property access. i.e.

Public Class RSSChannel
{
private string _title
private ArrayList _rssitems

public string Title
{
get { return _title; }
set { _title = value; }
}

public ArrayList RSSItems
{
get { return _rssitems;}
set { _rssitems =value; }
}
etc.....
}

I then try and add a RSSitem to the array list like so:

rsschannel.RSSItems.Add(rssitem);

But looking at the debug output it calls the get accessor; I'am clearly doing
something wrong here as I what to call set (and add the RSSitem to the
ArrayList)

What am I doing wrong.

You're doing nothing wrong - you *don't* want to be calling set, as
that would be replacing the current list reference with a different
list. Think about it as this process:

1) Find the current list
2) Add the item to the end of the list

Step 1 is a "get" action.

Jon
 
G

Guest

Hi Jon

Thanks, I had forgot to create an instance of the ArrayList ! Anyway you
have helped clean up why get was getting called and not set.

Many thanks
DH
 

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