[.net] sample data

Started by
0 comments, last by HNikolas 12 years, 7 months ago
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?

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.
[size=2]Ruby on Rails, ASP.NET MVC, jQuery and everything else web.. now also trying my hand on games.

This topic is closed to new replies.

Advertisement