Select to view content in your preferred language

How do I update Sample Data in C#?

576
1
09-23-2011 06:49 PM
wmthompson
Emerging Contributor
How do I update Sample Data in C#?

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?
0 Kudos
1 Reply
GalTalmor
Emerging Contributor
What do you mean "to create the data from outside"?
You can simply write its as a property (with set and get)

private static ObservableCollection<Product> m_Data;
public static ObservableCollection<Product> Data
{
    set { m_Data = value; }
    get 
    { 
            if (m_Data == null) m_Data = new ObservableCollection<Product>();
            return m_Data;
    }
}

0 Kudos