摘要: 1、使用FileStream读写文件文件头:using System;using System.Collections.Generic;using System.Text;using System.IO;读文件核心代码:byte[] byData = new byte[100];char[] charData = new char[1000];try{FileStream sFile = new FileStream("文件路径",FileMode.Open);sFile.Seek(55, SeekOrigin.Begin);sFile.Read(byData, 0, 10 阅读全文
posted @ 2014-02-27 17:57 zzg168 阅读(125) 评论(0) 推荐(0) 编辑
摘要: using System;usingSystem.Collections; usingSystem.ComponentModel; usingSystem.Data; usingSystem.Drawing; usingSystem.Web; usingSystem.Web.SessionState; usingSystem.Web.UI; usingSystem.Web.UI.WebControls; usingSystem.Web.UI.HtmlControls; namespaceWebApplication1.验证码 { /// ///完美随机验证码0.10 ///Verion:0.1 阅读全文
posted @ 2014-02-27 17:56 zzg168 阅读(253) 评论(0) 推荐(0) 编辑
摘要: 注意:转换为ICO后效果不好.源代码:using System;using System.Collections.Generic;using System.Text;using System.Drawing;using System.Drawing.Imaging;using System.IO;namespace paomiangege{ public class ImageConvert { private int ICON_W = 64; private int ICON_H = 64; public ImageConvert() { } //fileinpath,origaly pic 阅读全文
posted @ 2014-02-27 17:53 zzg168 阅读(916) 评论(0) 推荐(0) 编辑
摘要: 集合>哈希表类HashtableHashtable一种键值对的集合 ,哈希表内部的排列是无序的,而且哈希表没有提供排序方法。集合>哈希表类Hashtable>构造普通哈希表代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Collections;namespaceConsoleA 阅读全文
posted @ 2014-02-27 17:51 zzg168 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 1.dynamic ExpandoObject熟悉js的朋友都知道js可以这么写 :1var t = new Object(); 2t.Abc = ‘something’; 3t.Value = 243;现在这个js动态语言的特性,我们也可以在c#中使用了,前提是将一个变量声明为ExpandoObject类型。如下例:1static void Main(string[] args) 23dynamic t = new ExpandoObject(); 4t.Abc = "abc"5t.Value = 10000; 6Console.WriteLine("t' 阅读全文
posted @ 2014-02-27 17:50 zzg168 阅读(114) 评论(0) 推荐(0) 编辑
摘要: C#格式化数值结果表字符说明示例输出C货币string.Format("{0:C3}", 2)$2.000D十进制string.Format("{0:D3}", 2)002E科学计数法1.20E+0011.20E+001G常规string.Format("{0:G}", 2)2N用分号隔开的数字string.Format("{0:N}", 250000)250,000.00X十六进制string.Format("{0:X000}", 12)Cstring.Format("{0:000. 阅读全文
posted @ 2014-02-27 17:47 zzg168 阅读(154) 评论(0) 推荐(0) 编辑
摘要: ===================================================注:很久没有发文了,贴一篇新文吧。从Word直接贴过来的,没仔细排版,诸位海涵。有关DLR和C# 4动态特性的详细介绍,请参看本人拙著《.NET 4.0面向对象编程揭秘(应用篇)》,目前该书正处于编辑出版流程中,估计12月上市。与此书相关的技术资源,将陆续发布于博客园与CSDN的本人博客。=====================================================================================金旭亮 近几年来,在TIOBE公司每个 阅读全文
posted @ 2014-02-27 17:45 zzg168 阅读(209) 评论(0) 推荐(0) 编辑
摘要: C#引入了readonly修饰符来表示只读域,const来表示不变常量。顾名思义对只读域不能进行写操作,不变常量不能被修改,这两者到底有什么区别呢?只读域只能在初始化--声明初始化或构造器初始化--的过程中赋值,其他地方不能进行对只读域的赋值操作,否则编译器会报错。只读域可以是实例域也可以是静态域。只读域的类型可以是C#语言的任何类型。但const修饰的常量必须在声明的同时赋值,而且要求编译器能够在编译时期计算出这个确定的值。const修饰的常量为静态变量,不能够为对象所获取。const修饰的值的类型也有限制,它只能为下列类型之一(或能够转换为下列类型的):sbyte, byte, short 阅读全文
posted @ 2014-02-27 17:43 zzg168 阅读(136) 评论(0) 推荐(0) 编辑
摘要: The FindControl method of the System.Web.UI.Control class appears simple enough to use. In fact, the MSDN description of the method is one simple sentence: Searches the current naming container for the specified server control.The key to using FindControl is to invoke the method on the correct conta 阅读全文
posted @ 2014-02-27 17:42 zzg168 阅读(271) 评论(0) 推荐(0) 编辑
摘要: 原题如下:12(a桶 满的 有12斤油)斤桶里 取出6斤油 有 另外有8斤(b桶)和5斤(c桶)两个空桶 让程序输出取出这6斤油的步骤现在实现的算法可以配参数(定义有几个桶,初始有多少油,要得到多少油,都可以配),并且找出任意(多条线路或者找不到)满足条件的倒油线路图:运行效果:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->using System;using System.Collections.Generic;using System. 阅读全文
posted @ 2014-02-27 17:41 zzg168 阅读(181) 评论(0) 推荐(0) 编辑
摘要: 一.使用OleDb,这个法子好像不大好使.容易读错.引用System.Data.OleDb;/**///////返回Excel数据源//////文件路径///staticpublicDataSetExcelToDataSet(stringfilename){DataSetds;stringstrCon="Provider=Microsoft.Jet.OLEDB.4.0;"+"ExtendedProperties=Excel8.0;"+"datasource="+filename;OleDbConnectionmyConn=newOle 阅读全文
posted @ 2014-02-27 17:40 zzg168 阅读(492) 评论(0) 推荐(0) 编辑
摘要: 1///2///提取字符串中的数字字符串3///4///5///6publicstaticstringIsNumber(Stringstr)7{8stringreturnStr=string.Empty;9for(inti=0;i<str.Length;i++)10{11if(Char.IsNumber(str,i)==true)12{13returnStr+=str.Substring(i,1);14}15else16{17if(str.Substring(i,1)=="A"||str.Substring(i,1)=="")18{19return 阅读全文
posted @ 2014-02-27 17:37 zzg168 阅读(266) 评论(0) 推荐(0) 编辑
摘要: MFC 生成本机代码,自然是很快。可是,消息循环,减缓了界面显示速度。winform 封装了 win32 的api,多次进行P/invoke 操作 (大部分使用p/invoke操作封装),速度慢 。wpf是一种新的模型,不再使用win32 模型,自己新建模型,使用dx 作为新的显示技术,直接访问驱动程序,加快了运行速度,可是,这种模型,需要支持dx 9 的显卡,硬件要求高(你还能找到现代机器不支持dx9 的吗?)开发效率上,MFC<WPF<winform 尽管MFC开发界面执行效率高但是开发效率低,作为现在的项目开发来说时间跟开发效率往往能决定项目的成败,所以除非有特别的需求,否则 阅读全文
posted @ 2014-02-27 17:36 zzg168 阅读(710) 评论(0) 推荐(0) 编辑
摘要: 这一段公司有个项目,客户要求上传的图片要带上自定义的水印。以前也经常和朋友讨论C#图片水印方面的问题,但是从来没有实际操作过。所以,借这次项目的机会也研究了一下C#图片水印的功能!本人参考的是discuz论坛中的代码。这种方法是直接把要上传的图片先转化成System.Drawing.Image,而不用保存到服务器端的磁盘上,然后加上水印重新绘制,再保存到服务器端的磁盘上,下面就拿出来晒晒:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 1/ 阅读全文
posted @ 2014-02-27 17:35 zzg168 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 在做WinForm界面布局时,菜单和工具栏必不可少!但是MenuStrip和ToolStrip不能够对边框的样式直接设置,如果想实现菜单和工具栏之间的分割线就不容易实现;今天查阅了一下msdn找到了一个方法,和大家一块分享,如果有更好的办法的话可以贴出来,共同进步; 首先,创建一个CustomProfessionalRenderer类(类名可随便定义)继承自ToolStripProfessionalRenderer。代码如下:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighli 阅读全文
posted @ 2014-02-27 17:34 zzg168 阅读(466) 评论(0) 推荐(0) 编辑
摘要: using System;using System.Data;using System.Configuration;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Drawing;namespace Ne 阅读全文
posted @ 2014-02-27 17:32 zzg168 阅读(579) 评论(0) 推荐(0) 编辑
摘要: C#中new和override是继承中经常用到的两个关键字,但是往往有时候容易把这两个关键字的作用搞混淆。newC# new关键字表示隐藏,是指加上new关键字的属性或函数将对本类和继承类隐藏基类的同名属性或函数Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->publicclassA{publicvirtualvoidMethod(){Console.WriteLine("ThisMethodinClassA!");}}p 阅读全文
posted @ 2014-02-27 17:31 zzg168 阅读(137) 评论(0) 推荐(0) 编辑
摘要: 对属性或索引器使用访问修饰符受以下条件的制约:· 不能对接口或显式接口成员实现使用访问器修饰符。· 仅当属性或索引器同时具有 set 和 get 访问器时,才能使用访问器修饰符。这种情况下,只允许对其中一个访问器使用修饰符。· 如果属性或索引器具有 override 修饰符,则访问器修饰符必须与重写的访问器的访问器(如果有的话)匹配。· 访问器的可访问性级别必须比属性或索引器本身的可访问性级别具有更严格的限制。· public class Parent· {· public virtual int TestProperty& 阅读全文
posted @ 2014-02-27 17:30 zzg168 阅读(163) 评论(0) 推荐(0) 编辑
摘要: 请先下载http://asprise.com/product/ocr/index.php?lang=csharp 的SDK.里面提供了详细的OCR方法,如下:将发现图像框picbVeryfyCode里的文字和文本框.txtVeryfyCode.Text是一致的.数字识别率我碰到的几乎是100%http://blog.csdn.net/crabo/[DllImport("AspriseOCR.dll")]static extern string craboOCR(string file, int type);private void GetVeryfyCode(){ if(F 阅读全文
posted @ 2014-02-27 17:29 zzg168 阅读(653) 评论(0) 推荐(0) 编辑
摘要: 将oledb读取的excel数据快速插入的sqlserver中,很多人通过循环来拼接sql,这样做不但容易出错而且效率低下,最好的办法是使用bcp,也就是System.Data.SqlClient.SqlBulkCopy 类来实现。不但速度快,而且代码简单,下面测试代码导入一个6万多条数据的sheet,包括读取(全部读取比较慢)在我的开发环境中只需要10秒左右,而真正的导入过程只需要4.5秒。using System;using System.Data;using System.Windows.Forms;using System.Data.OleDb;namespace WindowsApp 阅读全文
posted @ 2014-02-27 17:28 zzg168 阅读(172) 评论(0) 推荐(0) 编辑