C# 虚函数使用范例using System;namespace Test2 { class Plane { public double TopSpeed() { return 300.0D; } } class Jet : Plane { public double TopSp……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1821浏览  958个赞
   C#构造函数、静态构造函数、析构函数的用法using System;class Test2 { static int i; static Test2() { // a constructor for the entire class called //once before……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2728浏览  636个赞
   C#格式化输出内容nt k = 16;Console.WriteLine(" '{0,-8}'",k); // produces: '16 'Console.WriteLine(" '{0,8}'",k); // pro……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1665浏览  2102个赞
   C# xml文件反序列化读入数据到objectpublic static object DeSerializeFromXmlString(System.Type typeToDeserialize, string xmlString) { byte[] bytes = System.Text.Encoding.UTF8.GetBytes(xml……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2652浏览  2533个赞
   C#简单的写入xml文件的方法StringWriter stringWriter = new StringWriter();XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);xmlTextWriter.Formatting = Formatting.Indented;xml……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2035浏览  1933个赞
   C#写入对象或者集合类型数据到xml文件public static string SerializeToXmlString(object objectToSerialize) { MemoryStream memoryStream = new MemoryStream(); System.Xml.Serialization.XmlSer……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1918浏览  1846个赞
   C# 原始的方法写入xml文件static void writeTree(XmlNode xmlElement, int level) { String levelDepth = ""; for(int i=0;i<level;i++) { levelDepth += " &quo……继续阅读 »  水墨上仙  5年前 (2021-03-12)  3093浏览  2185个赞
   C#通过流写入一行数据到文件using System;using System.IO;public class WriteFileStuff {public static void Main() { FileStream fs = new FileStream("c:\\tmp\\WriteFileStuff.txt&qu……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1316浏览  364个赞
   C#一次性写入全部文件到文件using System;namespace PlayingAround { class ReadAll { public static void Main(string[] args) { string myText = "Line1" + Enviro……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1452浏览  2250个赞
   C#逐行读取文件,对于大文件的读取非常有用StreamReader sr = new StreamReader("fileName.txt");string line;while((line= sr.ReadLine()) != null) { Console.WriteLine("xml template:&quo……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1952浏览  2552个赞
   C#读取文件的所有行到数组using System;namespace PlayingAround { class ReadAll { public static void Main(string[] args) { string[] lines = System.IO.File.ReadAllLine……继续阅读 »  水墨上仙  5年前 (2021-03-12)  3166浏览  1800个赞
   C#通过文件流读取文件内容public static string getFileAsString(string fileName) { StreamReader sReader = null; string contents = null; try { FileStream fileStream = new FileSt……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2807浏览  1228个赞
   C#把整个文件的内容读入字符串变量using System;namespace PlayingAround { class ReadAll { public static void Main(string[] args) { string contents = System.IO.File.ReadAl……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1841浏览  732个赞
   c#通过DES加密算法加密大文件using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.U……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2506浏览  144个赞
   一个C#控制台程序演示hello worldusing System;public class HelloWorld{ public static void Main(string[] args) { Console.Write("Hello World!"); }}……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2956浏览  576个赞
   C# LINQ判断素数的简单代码static bool IsPrime(int n){ return Enumerable.Range(2, (int) Math.Sqrt(n)-1).All(i => n%i != 0);}……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1769浏览  1181个赞
   C# 符合RFC3986标准的urlencode 类 /// <summary> /// Provides implementation of RFC3986 Percent Encoding mechanism. /// </summary> public class RFC3986Encoder ……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2731浏览  1169个赞
   C#用钩子获得按键信息实例 窗体相关代码:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;us……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2229浏览  639个赞
   C#访问SqlServer设置链接超时,这段代码设置超时时间为60秒,默认为30秒using (connection) { SqlCommand sqlcommand = connection.CreateCommand(); sqlcommand.CommandTimeout = 60; //default is 30 seconds……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1767浏览  2429个赞
   C#查询SqlServer数据库并返回单个值static public string GetSqlAsString(string sqlText, SqlParameter[] sqlParameters, string databaseConnectionSt……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2881浏览  1145个赞
   之前我贴过一段很简单的C#生成plist文件的代码,但是反过来如果要读取plist文件呢?有没有实现这样功能的类库呢?答案是肯定的,下午在网上找了一个iphone-plist-net库试用了一下感觉很是方便。来源:http://blog.csdn.net/wangqiuyun/article/details/7931972 //写……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1969浏览  2625个赞
   C#从XmlDocument返回一个指定的属性string total = xmlDocument.SelectSingleNode("Surveys/Survey[@name='Beer']/cellName[@name='MatureBlueCollarMen']").Attributes……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1761浏览  2118个赞
   C#输出xmlNodeList到控制台 public static string ToHTML(XmlNodeList xmlNodeList) { StringWriter stringWriter = new StringWriter(); XmlTextWriter xmlTextWriter = new Xm……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2618浏览  2835个赞
   C# 执行外部命令///<summary> ///executes a system command from inside csharp ///</summary> ///<param name="cmd">a dos type command like "isql ...&qu……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1366浏览  2411个赞
   C#从 web service检索xml文档并应用 XSLT public class ScreenerQuestionsToAsk : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { GetSurv……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1205浏览  325个赞
   C# FTP操作类using System;using System.Collections.Generic;using System.Text;using System.Net;using System.IO;namespace Utility{ public class FtpUpDown { strin……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2339浏览  2725个赞
   C#实现文件下载,支持断点续传using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.IO;using System.Text;using System.Net;na……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2936浏览  2214个赞
   C#字符串转换成字节数组using System.Text;public static byte[] ConvertStringToByteArray(string stringToConvert){ return (new UnicodeEncoding()).GetBytes(stringToConvert);}……继续阅读 »  水墨上仙  5年前 (2021-03-12)  3543浏览  1991个赞
   C#转换集合类型为html代码输出public static string ToHTML(Hashtable hashtable) { string tmp = ""; IDictionaryEnumerator myEnumerator = hashtable.GetEnumerator(); whi……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2876浏览  1466个赞
   C# 将字符串转换成整形、double或者dateusing System;class Parse {/// <summary>/// Example of various Parse methods/// </summary>private static void Main() { //all the typ……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2060浏览  658个赞
   C# 读取QueryString全部数据并输出using System.Collections;using System.Collections.Specialized;... NameValueCollection collection = Request.QueryString; String[] keyArray = collectio……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1483浏览  2496个赞
   C#从控制台读取字符串using System;class ReadLine{ public static void Main() { Console.Write("Please enter your favorite animal: "); string animal = Console.Rea……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1855浏览  2414个赞
   C#下载网页,即使网页404或者500错误public static string GetWebPageAsString(string url){ HttpWebRequest httpWebRequest = (HttpWebRequest) WebRequest.Create(url); HttpWebResponse httpW……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2787浏览  1961个赞
   C#计算过了多长时间 DateTime startTime = DateTime.Now; // do stuff TimeSpan elapsed = DateTime.Now - startTime; Console.WriteLine("response time: {0}",elapsed.TotalSeconds);……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2728浏览  1159个赞
   下面对于Fibnaci数列作基本介绍:这里Fibnaci代表数组名,n代表索引。如:Fibnaci基数列:1,1,2,3,5,8…当n2时:Fibnaci(n)=Fibnaci(n-1)+Fibnaci(n-2)我们可以使用递归或者迭代等方法来进行算法编程,这里介绍迭代方法。其他算法非递归方法也可以参照如下方式。   public Lis……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2202浏览  191个赞
   C# 简单下载网页的方法string xml;using(WebClient client = new WebClient()) { xml = client.DownloadString(url); }……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2284浏览  1604个赞
   c#实现人民币大小写转换的代码using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Utility{ /// <summary> ///金钱转换成大写 DBA群: 22598298……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1256浏览  1693个赞
   C# 用Log4net记录日志代码演示 1、引入Log4net.dll到项目中2、在global.asax的程序启动服务添加代码:protected void Application_Start(Object sender, EventArgs e) { log4n……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1973浏览  2348个赞
   C#验证码识别类,可以用于识别各种验证码的算法演示using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using System.Drawing.Imaging;using System.R……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1327浏览  1523个赞
   C#获取指定月指定周的日期范围 根据当前时间获取本月开始日期和结束日期 /// <summary> /// 获取指定月份指定周数的开始日期 /// </summary> /// <param name="year">年份</par……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2212浏览  2675个赞
   用EnumWindows 函数将枚举计算机上的所有现有窗口,但我们用System.Diagnostics名字空间的静态函数Process.GetProcesses()可以避免EnumWindows的互操作性问题Using System.Diagnostics; ... foreach ( Process p in Process.GetProc……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1954浏览  316个赞
   C#显示出正在运行的所有进程Using System.Diagnostics; ... foreach ( Process p in Process.GetProcesses() ) Console.WriteLine( p ); // string s = p.ToString(); ……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1330浏览  1769个赞
   C#确保只有一个实例在运行public static Process RunningInstance() { Process current = Process.GetCurrentProcess(); Process[] processes = Process.GetProcessesByName (current.ProcessName); ……继续阅读 »  水墨上仙  5年前 (2021-03-12)  1582浏览  910个赞
   C#获得本机ip地址string s=""; System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList; for (int i = 0; i < addressList.Length; i ++) { s……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2670浏览  1740个赞
   C#解压GZip文件代码 public void ungzip(string path, string decomPath, bool overwrite) { //for overwriting purposes if (File.Exists(decomPath)) ……继续阅读 »  水墨上仙  5年前 (2021-03-12)  2459浏览  1160个赞