Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a class that has within it subclasses...

 

I am trying to implement a collection of those subclasses as a property of the top most class such that I can utilize a .add() type funcation.

 

such as follows:

 

dim dt as datatable

dt.rows.add(dt.newrow)

 

I would like to use this strucature with my classes

 

I have implemented IEnumerator, IEnumerable etc. and am pretty happy with the results - just need this last little thing :)

 

Help

 

Could be that I am working on little sleep...

Posted

You can create a strongly typed collection class (for storing the subclasses) with an add method. Then create a property of that class in the main class.

 

// pseudo code
public class Team
{
	public PlayerCollection Players
	{
		get { return _players; }
		set { _players = value; }
	}
}

public class Player
{
}

public class PlayerCollection : CollectionBase
{
	public void Add(Player obj)
	{
	}
}

Anybody looking for a graduate programmer (Midlands, England)?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...