|
沙发

楼主 |
发表于 2006-3-29 08:33:42
|
只看该作者
<p>网络方面的: <br/>十八、取得IP地址: <br/>using System; <br/>using System.Net; </p><p>class GetIP <br/>{ <br/>public static void Main() <br/>{ <br/>IPHostEntry ipEntry = Dns.GetHostByName ("localhost"; <br/>IPAddress [] IpAddr = ipEntry.AddressList; <br/>for (int i = 0; i < IpAddr.Length; i++) <br/>{ <br/>Console.WriteLine ("IP Address {0}: {1} ", i, IpAddr.ToString ()); <br/>} <br/>} <br/>}</p><p>十九、取得机器名称: <br/>using System; <br/>using System.Net; </p><p>class GetIP <br/>{ <br/>public static void Main() <br/>{ <br/>Console.WriteLine ("Host name : {0}", Dns.GetHostName()); <br/>} <br/>} </p><p>二十、发送邮件: <br/>using System; <br/>using System.Web; <br/>using System.Web.Mail; </p><p>public class TestSendMail <br/>{ <br/>public static void Main() <br/>{ <br/>try <br/>{ <br/>// Construct a new mail message </p><p>MailMessage message = new MailMessage(); <br/>message.From = "<a href="mailto:from@domain.com">from@domain.com</a>"; <br/>message.To = "<a href="mailto:pengyun@cobainsoft.com">pengyun@cobainsoft.com</a>"; <br/>message.Cc = ""; <br/>message.Bcc = ""; <br/>message.Subject = "Subject"; <br/>message.Body = "Content of message"; </p><p>//if you want attach file with this mail, add the line below </p><p>message.Attachments.Add(new MailAttachment("c:\\attach.txt", MailEncoding.Base64)); </p><p>// Send the message </p><p>SmtpMail.Send(message); <br/>System.Console.WriteLine("Message has been sent"; <br/>} </p><p>catch(Exception ex) <br/>{ <br/>System.Console.WriteLine(ex.Message.ToString()); <br/>} </p><p>} <br/>}</p><p>二十一、根据IP地址得出机器名称: <br/>using System; <br/>using System.Net; </p><p>class ResolveIP <br/>{ <br/>public static void Main() <br/>{ <br/>IPHostEntry ipEntry = Dns.Resolve("172.29.9.9"; <br/>Console.WriteLine ("Host name : {0}", ipEntry.HostName); <br/>} <br/>}</p><p>GDI+方面的: <br/>二十二、GDI+入门介绍: <br/>using System; <br/>using System.Drawing; <br/>using System.Collections; <br/>using System.ComponentModel; <br/>using System.Windows.Forms; <br/>using System.Data; </p><p>public class Form1 : System.Windows.Forms.Form <br/>{ <br/>private System.ComponentModel.Container components = null; </p><p>public Form1() <br/>{ <br/>InitializeComponent(); <br/>} </p><p>protected override void Dispose( bool disposing <br/>{ <br/>if( disposing <br/>{ <br/>if (components != null) <br/>{ <br/>components.Dispose(); <br/>} <br/>} <br/>base.Dispose( disposing ; <br/>} </p><p>#region Windows Form Designer generated code </p><p>private void InitializeComponent() <br/>{ <br/>this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); <br/>this.ClientSize = new System.Drawing.Size(292, 273); <br/>this.Name = "Form1"; <br/>this.Text = "Form1"; <br/>this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); <br/>} <br/>#endregion </p><p><br/>[STAThread] <br/>static void Main() <br/>{ <br/>Application.Run(new Form1()); <br/>} </p><p>private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) <br/>{ <br/>Graphics g=e.Graphics; <br/>g.DrawLine(new Pen(Color.Blue),10,10,210,110); <br/>g.DrawRectangle(new Pen(Color.Red),10,10,200,100); <br/>g.DrawEllipse(new Pen(Color.Yellow),10,150,200,100); <br/>} <br/>}</p><p>XML方面的: <br/>二十三、读取XML文件: <br/>using System; <br/>using System.Xml; </p><p>class TestReadXML <br/>{ <br/>public static void Main() <br/>{ </p><p>XmlTextReader reader = new XmlTextReader("C:\\test.xml"; <br/>reader.Read(); </p><p>while (reader.Read()) <br/>{ <br/>reader.MoveToElement(); <br/>Console.WriteLine("XmlTextReader Properties Test"; <br/>Console.WriteLine("==================="; </p><p>// Read this properties of element and display them on console </p><p>Console.WriteLine("Name:" + reader.Name); <br/>Console.WriteLine("Base URI:" + reader.BaseURI); <br/>Console.WriteLine("Local Name:" + reader.LocalName); <br/>Console.WriteLine("Attribute Count:" + reader.AttributeCount.ToString()); <br/>Console.WriteLine("Depth:" + reader.Depth.ToString()); <br/>Console.WriteLine("Line Number:" + reader.LineNumber.ToString()); <br/>Console.WriteLine("Node Type:" + reader.NodeType.ToString()); <br/>Console.WriteLine("Attribute Count:" + reader.value.ToString()); <br/>} <br/>} <br/>} </p><p>二十四、写XML文件: <br/>using System; <br/>using System.Xml; </p><p>public class TestWriteXMLFile <br/>{ <br/>public static int Main(string[] args) <br/>{ <br/>try <br/>{ <br/>// Creates an XML file is not exist </p><p>XmlTextWriter writer = new XmlTextWriter("C:\\temp\\xmltest.xml", null); <br/>// Starts a new document </p><p>writer.WriteStartDocument(); <br/>//Write comments </p><p>writer.WriteComment("Commentss: XmlWriter Test Program"; <br/>writer.WriteProcessingInstruction("Instruction"," erson Record"; <br/>// Add elements to the file </p><p>writer.WriteStartElement("p", "person", "urnerson"; <br/>writer.WriteStartElement("LastName",""; <br/>writer.WriteString("Chand"; <br/>writer.WriteEndElement(); <br/>writer.WriteStartElement("FirstName",""; <br/>writer.WriteString("Mahesh"; <br/>writer.WriteEndElement(); <br/>writer.WriteElementInt16("age","", 25); <br/>// Ends the document </p><p>writer.WriteEndDocument(); <br/>} <br/>catch (Exception e) <br/>{ <br/>Console.WriteLine ("Exception: {0}", e.ToString()); <br/>} <br/>return 0; <br/>} <br/>} </p> |
|