brentnewbury
Newcomer
Hiya all,
I'm not a newbie to .NET by any means, but I've obviously missed something big here.
For some reason I can't seem to get indexed properties to work! Well, not in the way I want (and think to be most logical), I can get them to work like:
but not like this:
I know I seem dumb, but to me it doesn't seem logical to have the item itself manage it's own collection. To me it seems more logical to have the owning class manage a collection of its subordinates.
Here's the code I would like to use:
Do any of you have any advice?
Regards,
Brent
I'm not a newbie to .NET by any means, but I've obviously missed something big here.
For some reason I can't seem to get indexed properties to work! Well, not in the way I want (and think to be most logical), I can get them to work like:
Code:
public int this[int index]
{
get { ... }
set { ... }
}
Code:
public int Item[int index]
{
get { ... }
set { ... }
}
Here's the code I would like to use:
Code:
using System;
using System.Collections.Generic;
public class Collector
{
private List<Item> _collection;
public Item Items[int index]
{
get { return this._collection[index]; }
set { this._collection[index] = (Item)value; }
}
// Other members, properties, and methods
public class Item
{
// Members, properties, and methods
}
}
Regards,
Brent
Last edited: