using System.Collections.Specialized; using System.Xml; // Create a VariableDictionary VariableDictionary dict = new VariableDictionary(); // Add some data to the dictionary dict.Add("Name", "John"); dict.Add("Age", 25); // Save the dictionary to an XML file XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("Dictionary"); doc.AppendChild(root); dict.Save(root); // Load the data from the XML file VariableDictionary dict2 = new VariableDictionary(); dict2.Load(root);
using System.Collections.Specialized; using System.Data.SqlClient; // Create a VariableDictionary VariableDictionary dict = new VariableDictionary(); // Add some data to the dictionary dict.Add("Name", "John"); dict.Add("Age", 25); // Save the dictionary to a database SqlConnection conn = new SqlConnection("..."); SqlCommand cmd = new SqlCommand("INSERT INTO MyTable (Data) VALUES (@Data)", conn); SqlParameter param = new SqlParameter("@Data", dict.GetDataString()); cmd.Parameters.Add(param); cmd.ExecuteNonQuery(); // Load the data from the database VariableDictionary dict2 = new VariableDictionary(); SqlCommand cmd2 = new SqlCommand("SELECT Data FROM MyTable WHERE Id=@Id", conn); SqlParameter param2 = new SqlParameter("@Id", 1); cmd2.Parameters.Add(param2); SqlDataReader reader = cmd2.ExecuteReader(); reader.Read(); dict2.LoadFromString(reader.GetString(0));Both examples use the `System.Collections.Specialized` namespace, which is part of the .NET Framework.