Sunday, December 16, 2007

how to iterate key and value from hashTable

Hashtable ht = new Hashtable();
ht.Add("A1", "a111111");
ht.Add("A2", "a222222");
ht.Add("A3", "a333333");
ht.Add("A4", "a444444");
ht.Add("A5", "a555555");
ht.Add("A6", "a666666");
ht.Add("A7", "a777777");
ht.Add("A8", "a888888");

IDictionaryEnumerator iDict;
iDict = ht.GetEnumerator();

while (iDict.MoveNext())
{
string key = iDict.Key.ToString();
string Value = iDict.Value.ToString();
}

Sunday, December 9, 2007

Evaluating string expression. ex: "2+3"

double D= (double)new System.Xml.XPath.XPathDocument
(new StringReader("")).CreateNavigator().Evaluate
(string.Format("number({0})", new
System.Text.RegularExpressions.Regex(@"([\+\-\*])")
.Replace(TextBox1.Text, " ${1} ")
.Replace("/", " div ")
.Replace("%", " mod ")));

TextBox2.Text = D.ToString();


Note: Above will evaluate expression in Textbox1.Text