If you want to serialize the dictionary to a file, I suggest you refer here, here and here.
Update
Be sure to look at all the links as there is more than one way to do this, but this is one way - by following this information and adding a public constructor of
public Item() { }
I could then do the following using XamlServices (you will need to add a reference to System.Xaml in your project):
class Program
{
static void Main()
{
Item newItem = new Item( "http://foo", "test1", 1.0 );
var values = new Dictionary<int,Item>();
values.Add(1,newItem);
using( StreamWriter writer = File.CreateText( "serialized.buf" ) )
{
XamlServices.Save( writer, values );
}
using( StreamReader tr = new StreamReader( "serialized.buf" ) )
{
Dictionary<int, Item> result = (Dictionary<int, Item>)XamlServices.Load( tr );
//do something with dictionary here
Item retrievedItem = result[1];
}
}
}
For information on databases, refer here and here.
If you want to get started using a database and WinForms I suggest this.
For deciding between a flat file and a database, refer to the answers here and here.
Sorry about all the links, but the info is out there (I know it is hard to find the right search terms when you are starting out).
In my own experience, whether or not you use a database depends on: -
- the complexity of the operations (queries,create,remove,updates,deletes) you want to do.
- the structure of the data you want to store.
- where the application will run. For example, if it will be an embedded application on a router (I take it your winforms app will not) then a file might be your only option.
- similar to the previous point, how lightweight and self-contained you want your application to be.
- the volume of data to be stored.