随笔分类 - C#
摘要:public byte[] FileToStream(string path) { byte[] s = null; StreamReader reader = new StreamReader(path); s = File.ReadAllBytes(path); return s; } public void StreamToFile(string path, byte[] bytes) { FileStream stream = null; stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileSha..
阅读全文
摘要:读XmlDocument document = new XmlDocument();document.Load("Data\\books.xml");List bookList = new List();foreach (XmlElement book in document.DocumentElement.ChildNodes){ string isbn = book.GetAttribute("ISBN").ToString();//属性 string genre = book.GetAttribute("genre").ToSt
阅读全文
摘要:需要用到void ReportLogForm_Deactivate(object sender, EventArgs e){ this.Close();}
阅读全文
摘要:注意: 是GridView的Double而不是GridControlprivate void gridView1_DoubleClick(object sender, EventArgs e){ GridView detailGrid = (sender as GridView); GridHitInfo hitInfo = (detailGrid.CalcHitInfo((e as MouseEventArgs).Location)); if (hitInfo != null && (hitInfo.InRow || hitInfo.InRowCell) &&
阅读全文
摘要://DEBUG必须大写,其它是不认的#if (DEBUG) Console.WriteLine("Debug");#else Console.WriteLine("非Debug");#endif
阅读全文
摘要:int[, ,] a = new int[3, 1, 3] { { {1,2,3} }, { {1,2,3} }, { {1,2,3} } };int[, ,] b = new int[3, 3, 1] { { { 1 }, { 2 }, { 3 } }, { { 4 }, { 5 }, { 6 } }, { { 7 }, { 8 }, { 9 } } };int[, ,] c = new int[1, 3, 3] { { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } } };
阅读全文
摘要:1、判定一个给定的C#路径是否有效,合法通过Path.GetInvalidPathChars或Path.GetInvalidFileNameChars方法获得非法的C#路径/文件名字符,可以根据它来判断路径中是否包含非法字符;2、如何确定一个C#路径字符串是表示目录还是文件使用Directory.Exists或File.Exist方法,如果前者为真,则路径表示目录;如果后者为真,则路径表示文件上面的方法有个缺点就是不能处理那些不存在的文件或目录。这时可以考虑使用Path.GetFileName方法获得其包含的文件名,如果一个路径不为空,而文件名为空那么它表示目录,否则表示文件;3、获得C#路.
阅读全文
摘要:private void SetEnable(bool flag){ Type type = this.richEditControl1.GetType(); //ric即RichEditControl实例 PropertyInfo info = type.GetProperty("HorizontalScrollBar", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); ScrollBarBase vs = (ScrollBarBase)info.GetValue(richEdi
阅读全文
摘要:判断文件夹是否存在,不存在就创建if (!Directory.Exists(ss)){Directory.CreateDirectory(ss);}判断文件是否存在,不存在就创建if (!File.Exists(ss)){ Directory.Create(ss);}保存一个二进制文件到磁盘指定路径/// 保存一个二进制文件到磁盘指定路径/// /// 磁盘路径/// 二进制数据/// privatevoid SaveFile(string path, byte[] bytes){ try { //若他们先将以二进制的形式存在于数据库中,则需要先读出来,然后将其转换为 byte //byte.
阅读全文
摘要:在字符处理过程中,我们可能需要对某些字符进行替换,而且可能会有多个字符,请比较下面两种写法:一个是用标准的replace函数,另外一个则是用正则表达式string input = "1,;3^e";string tt = input.Replace(",", "").Replace(";", "").Replace("^", "");string rr = Regex.Replace(input, @",|;|\^", "&q
阅读全文
摘要:通常情况下,若是你将用户控件写好了放入窗体中,若是有不合理的代码,则会弹出错误提示框,不让你放。若是你之前只是随便加了一个用户控件,并且没有什么问题,但后来你又把控件改坏掉了,那么你打开就会报错(在窗体内显示错误,选择"忽略并继续"还是可以打开设计界面的)。一般在设计时打开设计视图报"未将对象引用设置到对象的实例",基本上都是你在用户控件的构造方法及Form Load事件中写入了计算的代码。如以下代码放入到别的控件中就会报错:using System;using System.Collections.Generic;using System.Compon
阅读全文
摘要:string[] myArr = { "Overred", "Medloy", "Xiaoguai", "Hare" };ArraySegment arrSeg = new ArraySegment(myArr);for (int i = arrSeg.Offset; i myArrSegMid = new ArraySegment(myArr, 1, 3);则取myArr的索引从1到3的值,转自:http://www.cnblogs.com/chenxizhang/archive/2009/04/23/14417
阅读全文
摘要:Type trypInfo = typeof(Program);// Program为类名//获得方法名string str = "包括的方法名列表:\r\n";MethodInfo[] methodInfo = trypInfo.GetMethods();foreach (MethodInfo mInfo in methodInfo){ str += mInfo.ToString() + "\r\n";} 注:需要引用using System.Reflection;
阅读全文
摘要:dt.Columns.Add("ROWNUM", typeof(Int64));dt.Columns["ROWNUM"].SetOrdinal(0);
阅读全文
摘要:1、FACTORY 工厂方法追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西,虽然口味有所不同,但不管你带MM去麦当劳或肯德基,只管向服务员说“来四个鸡翅”就行了。麦当劳和肯德基就是生产鸡翅的Factory 工厂模式:客户类和工厂类分开。消费者任何时候需要某种产品,只需向工厂请求即可。消费者无须修改就可以接纳新产品。缺点是当产品修改时,工厂类也要做相应的修改。如:如何创建及如何向客户端提供。2、BUILDER建造者模式MM最爱听的就是“我爱你”这句话了,见到不同地方的MM,要能够用她们的方言跟她说这句话哦,我有一个多种语言翻译机,上面每种语言都有一个按键,见到MM我只要按对应
阅读全文
摘要:/// /// 清除html中的标记,只留下文字。/// /// /// public string ClearHTMLTags(string HTML){ if (string.IsNullOrEmpty(HTML)) return ""; string[] Regexs ={ @"", @"", //@"([\r\n])[\s]+",//换行 @"&(quot|#34);", @"&(amp|#38);", @"&(lt|#60);&qu
阅读全文
摘要:private void button2_Click(object sender, EventArgs e){ string file = ""; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = "c:\\";//注意这里写路径时要用c:\\而不是c:\ openFileDialog.Filter = "Html|*.html|Mht|*.mht|htm|*.htm"; openFileDialog.Rest
阅读全文
摘要:--存储数据:List<string> keyList = new List<string> { "a", "b", "c" };foreach (string key in keyList){ AppDomain.CurrentDomain.SetData(key, key + key);}--取数据foreach (string key in keyList){ object obj = AppDomain.CurrentDomain.GetData(key); Console.WriteLine(obj.
阅读全文
摘要:Console.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss-ffff"));
阅读全文
摘要:MemberwiseClone复制出来的字段也好,属性也好(不包括Address之类的类型),修改其中副本一个这些值,都不会影响到原值。但自定义的类,就不行了,只能通过深拷贝来实现不互相影响。
阅读全文