一、判断文件或文件夹是否存在
使用System.IO.File,要检查一个文件是否存在非常简单: 
bool exist = System.IO.File.Exists(fileName);

如果需要判断目录(文件夹)是否存在,可以使用System.IO.Directory:
bool exist = System.IO.Directory.Exists(folderName);

二、使用delegate类型设计自定义事件
在C#编程中,除了Method和Property,任何Class都可以有自己的事件(Event)。定义和使用自定义事件的步骤如下: 
(1)在Class之外定义一个delegate类型,用于确定事件程序的接口 
(2)在Class内部,声明一个public event变量,类型为上一步骤定义的delegate类型 
(3)在某个Method或者Property内部某处,触发事件 
(4)Client程序中使用+=操作符指定事件处理程序 

例子: // 定义Delegate类型,约束事件程序的参数

public delegate void MyEventHandler(object sender, long lineNumber) ;
public class DataImports
 { 
 
 // 定义新事件NewLineRead
 public event MyEventHandler NewLineRead ;public void ImportData()
 { 
 
 long i = 0 ; // 事件参数
 while()
 { 
 
 i++ ;
 // 触发事件
 if( NewLineRead != null ) NewLineRead(this, i);
 //...
 }
 //...
 }
 //...
 }

// 以下为Client代码

private void CallMethod()
 { 
 
 // 声明Class变量,不需要WithEvents
 private DataImports _da = null;
 // 指定事件处理程序
 _da.NewLineRead += new MyEventHandler(this.DA_EnterNewLine) ;
 // 调用Class方法,途中会触发事件
 _da.ImportData();
 }
 // 事件处理程序
 private void DA_EnterNewLine(object sender, long lineNumber)
 { 
 
 // ...
 }

三、IP与主机名解析 
使用可以实现与Ping命令行类似的IP解析功能,例如将主机名解析为IP或者反过来: private string GetHostNameByIP(string ipAddress)

{ 
 
 IPHostEntry hostInfo = Dns.GetHostByAddress(ipAddress);
 return hostInfo.HostName;
 }
 private string GetIPByHostName(string hostName)
 { 
 
 .IPHostEntry hostInfo = Dns.GetHostByName(hostName);
 return hostInfo.AddressList[0].ToString();
 }