Tuesday, May 12, 2009

Adding TimeSpan value in DataTime

DateTime today = DateTime.Now;
TimeSpan duration = new TimeSpan(days,hours,minutes, seconds);
DateTime result= today.Add(duration);

Convert string to DateTime in C#

DateTime date=DateTime.Parse('5/12/2009 12:26:32 PM');

Read a XML document with C#

using system.xml;

string price="";
string author="";

// initialize dom module
XmlDocument xmldoc = new XmlDocument();
// load xml
xmldoc.Load(books.xml);
XmlNodeList records = xmldoc.GetElementsByTagName("book");
foreach (XmlElement xe in records)
{
XmlElement elmt = (XmlElement)xe;
price= elmt.GetElementsByTagName("price")[0].InnerText;
author= elmt.GetElementsByTagName("author")[0].InnerText;

MessageBox.Show("Author="+author+"==> Price="+price);
}

books.xml

< books >
< book >
< author > abc < /author >
< price > 30 < /price >
< /book >
< book >
< author > xyz< /author >
< price > 100< /price >
</ book >

< books >

OUT PUT

Author=abc ==> Price=30
Author=xyz==> Price=100




Delegate in c#

// Declare the Delegate
public delegate void delegateName();

// Create the object of Delegate
delegateName dn= new Uploaddelegate(callme);


public static void callme
()
{
// code to do here
}