I have a C# program that retrieves data from a webpage and then organizes the content into a dictionary. So far the program get the data from the web every time I run it cause there is no alternative data source. The problem is that if I am offline I can't retrieve the data so I don't have data to work with. Can I save the entire dictionary locally so that I can then load it and run my analysis even if I am offline?
The dictionary to save is myData:
Dictionary<string, itemdata> myData = new Dictionary<string, itemdata>();
where the key is a string and represent the name of an item and itemdata in turn is defined as:
public class itemdata
{
// Fields
public double itemWeight;
public double itemSize;
public double itemPrice;
// class constructor
public itemdata(double myItemWeight, double myItemSize, double myItemPrice)
{
itemWeight= myItemWeight;
itemSize= myItemSize;
itemPrice= myItemPrice;
}
// Public properties (read only access to these fields)
public double myItemWeight
{
get { return itemWeight; }
}
public double myItemSize
{
get { return itemSize; }
}
public double myItemPrice
{
get { return itemPrice; }
}
}
So in my main class I retrieve some data for some items and then I populate:
itemdata myItemMap = new itemdata (itemWeight, itemSize, itemPrice)
and insert everything into the dictionary:
myData.Add(itemName, myItemMap);
Once all data have been retrieved and organized into the myData dictionary, I would like this to be saved locally.
Thanks for all the suggestions you gave me so far. Saving to XML seems to be a good choice but I would appreciate some clear example how to deal with my particular dictionary since it is not simply "one key and one value" but a slightly more complex "one key with multiple values/fields".