Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CollectionBase - simple question?

Status
Not open for further replies.

MattWoberts

Programmer
Oct 12, 2001
156
GB
Hi, I have created a collection class derived from CollectionBase, which holds a collection of simple structures.

It works nicely, but when I want to change the value of one of the entities in the collection, I expected the following code to work:

coll[0].x = 10;

But I get this error:

Cannot modify the return value of 'XXX.CollClass.this[int]' because it is not a variable.

Can anybody point me in the right direction? Ta!

---------------------

Code for the collection:

public class CollClass: CollectionBase
{
//strongly typed accessor
public EntityClass this[int index]
{
get
{
return (EntityClass ) this.List[index];
}
set
{
this.List[index] = value;
}
}

public void Add(EntityClass perfGraphDataEnt)
{
this.List.Add(perfGraphDataEnt);
}

}
 
Doh!

I have figured it out!

It was because it was a collection of structs, which are passed by value, rather than reference. Changing the entity struct to a class has sorted it!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top