随笔分类 -  C#

摘要:using System; using System.Collections.Generic; using System.Text; namespace CustomGenericCollection { #region 汽车的定义 public class Car { public string PetName; public int Speed; public Car(string name, int currentSpeed) { PetName = name; ... 阅读全文
posted @ 2012-02-10 15:31 清山博客 阅读(3873) 评论(0) 推荐(0)
摘要:int i=10;方法1:Console.WriteLine(i.ToString("D5"));方法2:Console.WriteLine(i.ToString().PadLeft(5,'0'));//推荐方法3:Console.WriteLine(i.ToString("00000"));在 C# 中可以对字符串使用 PadLeft 和 PadRight 进行轻松地补位。PadLeft(int totalWidth, char paddingChar) //在字符串左边用 paddingChar 补足 totalWidth 长度Pad 阅读全文
posted @ 2012-02-01 09:26 清山博客 阅读(93249) 评论(0) 推荐(8)
摘要:class Program { static void Main(string[] args) { System.Globalization.ChineseLunisolarCalendar chineseLunisolarCalendar = new System.Globalization.ChineseLunisolarCalendar(); DateTime date = DateTime.Now; int year = chineseLunisolarCalen... 阅读全文
posted @ 2012-01-11 13:26 清山博客 阅读(319) 评论(0) 推荐(0)
摘要:using System; using System.Data; using System.Text.RegularExpressions; using System.Xml; using System.IO; using System.Collections; using System.Data.SQLite; namespace SQLiteHelper { /// <summary> /// SQLiteHelper is a utility class similar to "SQLHelper" in MS /// Data Access Applic 阅读全文
posted @ 2012-01-05 20:15 清山博客 阅读(959) 评论(0) 推荐(0)
摘要:nt32. Parse (string)Int32.Parse (string str) method converts the string representation of a number to its 32-bit signed integer equivalent. It takes a string and tries to extract an integer from it and returns the integer. When s is a null reference, it will throwArgumentNullException. If str is not 阅读全文
posted @ 2011-12-15 16:49 清山博客 阅读(1479) 评论(0) 推荐(0)
摘要:比如需导出如下形式的报表:里面数据字段分类很多,又含公式统计等情况。解决方案:利用NPOI组件,制作导出模板,对单元格精确控制,通过读取单元格里的模板字段,进行数据匹配替换;模板形式如下:核心方法: /// <summary> /// 根据Excel模板单元格内容,找出单元格,并设置单元格的值 /// </summary> /// <param name="sheet">ExcelSheet</param> /// <param name="rowIndex">行索引</param> 阅读全文
posted @ 2011-12-14 09:58 清山博客 阅读(1703) 评论(1) 推荐(1)
摘要:利用SQLite数据库做了个笔记记录软件,加上搜索功能,方便自己记录东西所用。下载地址(请在安装了.net framework 3.0/3.5的机器上运行,win7默认已安装该运行时)参考资料: 1.KTDictSeg分词组件:http://www.cnblogs.com/eaglet/archive/2008/11/17/1335098.html 2.ICSharpCode.TextEditor 高亮文本编辑器:http://www.icsharpcode.net/ 3.SQlite 数据库:http://www.sqlite.org/download.html 阅读全文
posted @ 2011-10-30 12:52 清山博客 阅读(1506) 评论(0) 推荐(0)
摘要:方法1: using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.Threading; using System.Reflection; static class Program { private static Mutex singleton; /// <summary> /// The main entry point for the application. ... 阅读全文
posted @ 2011-10-12 20:35 清山博客 阅读(311) 评论(0) 推荐(0)
摘要:将Quartz.NET组建引入到WinFrom中时,遇到个问题,关闭程序后,进程任未结束。解决办法:在窗体关闭时,把调度器关闭就不会存在进程了。private void FormMain_FormClosing ( object sender , FormClosingEventArgs e )if (Scheduler.GetIntance()!= null ){ Scheduler.GetIntance().Shutdown()} 阅读全文
posted @ 2011-10-12 20:34 清山博客 阅读(527) 评论(0) 推荐(2)
摘要:RSA算法基于一个十分简单的数论事实:将两个大素数相乘十分容易,但那时想要对其乘积进行因式分解却极其困难,因此可以将乘积公开作为加密密钥。RSA算法是第一个能同时用于加密和数字签名的算法,也易于理解和操作。原理图:C# 代码实现:using System; using System.Collections.Generic; using System.Text; using System.Security.Cryptography; using Microsoft.Win32; using System.IO; namespace SRA { class Program { ... 阅读全文
posted @ 2011-09-03 18:16 清山博客 阅读(309) 评论(0) 推荐(0)
摘要:在ASP.Net中,Request.QueryString是System.Collections.Specialized.NameValueCollection类型,默认它是经过UTF-8解码的。如果你的url中的参数用的是GBK编码,将会在QueryString中得到一串乱码。怎么办?自己读原始的Query然后去解析?不用那么复杂,Framework已经帮你做好了处理的方法:string query = this.Request.Url.Query;System.Collections.Specialized.NameValueCollection queryString = System. 阅读全文
posted @ 2011-07-12 22:32 清山博客 阅读(420) 评论(0) 推荐(0)
摘要:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace WindowsFormsApplication1 { public static class GetGB2312StrokeCount { /// <summary> /// 获取字符串中所有汉字的笔画总和 /// </summary> /// <param name="cnWords&qu 阅读全文
posted @ 2011-07-11 08:29 清山博客 阅读(1933) 评论(0) 推荐(1)
摘要:using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Text.RegularExpressions; /// <summary> /// 汉字 阅读全文
posted @ 2011-07-10 13:46 清山博客 阅读(670) 评论(0) 推荐(0)
摘要:一般来说一个 HTML 文档有很多标签,比如“<html>”、“<body>”、“<table>”等,想把文档中的 img 标签提取出来并不是一件容易的事。由于 img 标签样式变化多端,使提取的时候用程序寻找并不容易。于是想要寻找它们就必须写一个非常健全的正则表达式,不然有可能会找得不全,或者找出来的不是正确的 img 标签。我们可以从 HTML 标签的格式去想应该怎么建这个正则表达式。首先要想一下 img 标签有几种写法,忽略大小写不看的话,下面列出 img 标签可能出现的几种情况。<img> <img/> <imgsrc= 阅读全文
posted @ 2011-07-06 22:20 清山博客 阅读(1574) 评论(0) 推荐(0)
摘要:蔡勒(Zeller)公式:w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1 公式中的符号含义如下,w:星期;c:世纪-1;y:年(两位数);m:月(m大于等于3,小于等于14,即在蔡勒公式中,某年的1、2月要看作上一年的13、14月来计算,比如2003年1月1日要看作2002年的13月1日来计算);d:日;[ ]代表取整,即只要整数部分。(C是世纪数减一,y是年份后两位,M是月份,d是日数。1月和2月要按上一年的13月和 14月来算,这时C和y均按上一年取值。)算出来的W除以7,余数是几就是星期几。如果余数是0,则为星期日。 以2049年10月1日(100周年国庆)为例, 阅读全文
posted @ 2011-07-05 21:46 清山博客 阅读(205) 评论(0) 推荐(0)
摘要:思路非常简单,且没有任何位数限制!例如: 401,0103,1013读作: 肆佰零壹[亿]零壹佰零叁[万]壹仟零壹拾叁咱们先按每四位一组 从左到右,高位到低位分别"大声朗读"一下:"肆佰零壹" 单位是: "[亿]""壹佰零叁" 单位是: "[万]""壹仟零壹拾叁" 单位是 "" (相当于没有单位)很容易发现,每四位: 只有 千位,百位,十位,个位 这四种情况!我们把 [万],[亿] 当作单位就可以了!这就是规律了!简单吧!依据该思路,只用区区不到 50 行 阅读全文
posted @ 2011-07-05 21:41 清山博客 阅读(360) 评论(0) 推荐(0)
摘要:using System; using System.Xml; using System.Text; using System.Net; using System.IO; using System.Collections; using System.Text.RegularExpressions; public class App { public static void Main() { string strCode; ArrayList alLinks; Console.Write("请输入一个网页地址:"); ... 阅读全文
posted @ 2011-07-05 21:32 清山博客 阅读(512) 评论(0) 推荐(0)
摘要:启动进程: private void StartProcess(){ try { if (!CheckProcessExists()) { Process p = new Process(); p.StartInfo.FileName = System.IO.Path.Combine(Application.StartupPath, "DataTool.exe"); p.StartInfo.Arguments = "DataTool.exe"; ... 阅读全文
posted @ 2011-06-25 15:07 清山博客 阅读(16286) 评论(0) 推荐(0)
摘要:在网站或应用程序时,经常会用到配置文件,而这些配置文件一般多是xml文档,在开发配置文件过程中,可以采用下面的思路: 每个配置文件对应一个实体类,添加配置文件内容时,就new一个配置实体类并给这个类的属性进行赋值,然后【序列化】为xml,接着保存到文件; 读取时,直接读取前面序列化的xml文档,然后【反序列化】为对应的实体类,通过对实体类的访问以得到配置文件。用到的主要函数:设置保存配置信息: /// <summary> /// 更新配置信息,将配置信息对象序列化至相应的配置文件中,文件格式为带签名的UTF-8 /// </summary> /// <typepa 阅读全文
posted @ 2011-05-21 22:44 清山博客 阅读(1462) 评论(0) 推荐(0)
摘要:序列化对象为xml: /// <summary> /// 序列化对象 /// </summary> /// <typeparam name="T">对象类型</typeparam> /// <param name="t">对象</param> /// <returns></returns> public static string Serialize<T>(T t) { using (StringWriter sw = new StringWrit 阅读全文
posted @ 2011-05-21 22:37 清山博客 阅读(265) 评论(0) 推荐(0)