Jump to content
  • Advertisement
Sign in to follow this  
athono

[.net] sample data

This topic is 2639 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have this sample data. Right now it is defined in a seperate C# file like this:
public class SampleData
{

public static ObservableCollection<Product> GetSampleData()
{
ObservableCollection<Product> teams = new ObservableCollection<Product>();
}
}

and I load the obsevableCollection inside GetSampleData().

It works and I am able to get the sample data anywhere in my program.

But how can I redesign this code so that I can create the sample data on the fly from outside the class?

Share this post


Link to post
Share on other sites
Advertisement
The code you provided does not compile. Is it intended or you have missed something?

In addition, can you provide some more information about the context of this snippet so I can give more helpful reply. I do not entirely understand if you want the collection to be static(shared across all the instances of the class) or not.

What I understand currently is that:
1. You want a wrapper class around the collection.
2. Fetch the collection with GetSampleData function.

public class SampleData
{
private ObservableCollection<Product> teams = new ObservableCollection<Product>();

// Everything related to collection manipulation
//
public void Add(Product add)
{
teams.Add(add);
}

public void Remove(Product rem)
{
teams.Remove(rem);
}

public int this[Product i]
{
get { return teams; }
set { teams = value; }
}

public IEnumerator<Product> GetEnumerator()
{
return teams.GetEnumerator();
}

// Class methods
//
public ObservableCollection<Product> GetSampleData()
{
return teams;
}
}


Using the class above is pretty much pointless since only the GetSampleData is a special and everything else is already implemented in the ObservableCollection class so instead of it, I would instantiate the ObservableCollection<Product> directly instead, unless you will add some confirmation logic in the functions above.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!