private void button_result_clicked(object sender, EventArgs e) { label2.Text = label1.Text; string expression = label1.Text.Trim(); try { var result = new System.Data.DataTable().Compute(expression, null); if (result.GetType() == typeof(double)) { result = Math.Round((double)result, 5); } if (result.GetType() == typeof(decimal)) { result = Math.Round((decimal)result, 5); } string res = Convert.ToString(result); if (res.Contains(',')) { res = res.Replace(',', '.'); } label1.Text = res; } catch (Exception) { label1.Text = "Error"; } }
public static void Serialization() { // http://www.java2s.com/Tutorial/CSharp/0220__Data-Structure/SerializeanArrayListobjecttoabinaryfile.htm // http://www.java2s.com/Tutorial/CSharp/0220__Data-Structure/DeserializeanArrayListobjectfromabinaryfile.htm System.Data.DataTable dt = new System.Data.DataTable(); dt.Columns.Add("abc", typeof(string)); dt.Columns.Add("def", typeof(int)); System.Data.DataRow dr = dt.NewRow(); dr["abc"] = "test1"; dr["def"] = 123; dt.Rows.Add(dr); dr = dt.NewRow(); dr["abc"] = "test2"; dr["def"] = 456; dt.Rows.Add(dr); System.Data.DataSet ds = new System.Data.DataSet(); ds.Tables.Add(dt); Console.WriteLine("tname: " + dt.GetType().FullName); cSessionData ObjectToSerialize1 = new cSessionData("key1", "value1"); cSessionData ObjectToSerialize2 = new cSessionData("key2", "value2"); cSessionData ObjectToSerialize3 = new cSessionData("key3", dt); System.Collections.ArrayList al = new System.Collections.ArrayList(); al.Add(ObjectToSerialize1); al.Add(ObjectToSerialize2); al.Add(ObjectToSerialize3); string strSerializedItem = Serialize(al); Console.WriteLine(strSerializedItem); Deserialize(strSerializedItem); }