随笔分类 -  C#

摘要:GeHashCode三原则:1. 如果两个对象相等(由operator==定义),它们必须产生相同的散列码。否则,这样的散列码不能用来查找容器中的对象。2. 对于任何一个对象A,A.GetHashCode()必须是一个实例不变式(invariant)。即不管在A上调用什么方法,A.GetHashCode()都必须总是返回相同的值。这可以确保放在“散列桶”中的对象总是位于正确的“散列桶”中。3. 对于所有的输入,散列函数应该在所有整数中产生一个随机的分布。这样,我们才能从一个散列容器上获得效率的提升。Object.GetHashCode满足原则1和原则2,在哈希表(Hashtable,Dicti 阅读全文
posted @ 2011-05-31 18:59 再快一点 阅读(311) 评论(0) 推荐(1)
摘要:using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;using System.Reflection;using System.Threading;namespace EbookToBBs{ public class Tool { public static Type RtbType = typeof(RichTextBox); /// <summary> /// 停止一个线程,如果没有停止则方法不返回 /// </summary> /// & 阅读全文
posted @ 2011-05-04 18:21 再快一点 阅读(451) 评论(0) 推荐(0)
摘要:public class DataHelper { const string DEFSTR = ""; /// <summary> /// 根据一个类型,获取其默认值,数字默认是为0,字符串默认值为一个空字符串 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> static T GetDefault<T>() { T t = default(T); //如果是字符串类型, 阅读全文
posted @ 2011-04-12 10:14 再快一点 阅读(4625) 评论(0) 推荐(0)
摘要:class.cst内容如下:<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" ResponseEncoding="utf-8"%><%@ Assembly Name="System.Windows.Forms" %><%@ Import Namespace="System.Windows.Forms" %> <script runat="temp 阅读全文
posted @ 2011-03-22 20:27 再快一点 阅读(255) 评论(0) 推荐(0)
摘要:最近发现以前写的下面两个方法都有错误,default(string) 是null ,null is string 返回falsestatic class Extend { const string def = "dd"; public static T GetValue<T>(this DataRow dr, string name) { try { if (dr[name] == DBNull.Value) { object o = def; return (T)o; } else { return (T)dr[name]; } } catch (Argume 阅读全文
posted @ 2010-11-25 20:36 再快一点 阅读(366) 评论(1) 推荐(0)
摘要:public static void SendMailUseGmail(string gmailAddress, string gmailPwd, string name, string toAddress, string info, string title) { System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); msg.To.Add(toAddress); msg.From = new MailAddress(toAddress, name, System.Text.Encoding.UTF8); m 阅读全文
posted @ 2010-11-10 21:02 再快一点 阅读(249) 评论(0) 推荐(0)
摘要:int num = 50000000; Stopwatch wat = new Stopwatch(); string[] arr=new string[num]; for (int i = 0; i < num; i++) { // arr[i] = "";与 arr[i] = string.Empty;和 arr[i] = "字符串";所占内存差不错 //但是,arr[i] = "5"... 阅读全文
posted @ 2010-10-08 12:13 再快一点 阅读(371) 评论(0) 推荐(0)
摘要:int num = 1000000; B b = new B(); B[] arr=new B[num]; B[] mmm = new B[num]; for (int i = 0; i num; i++) { arr[i] = new B();     //下面两句代码只能选一句,运行,在任务管理器中查看程序的内存占用量      //mmm[i]=new B(); //若运行这一句,发现内存翻倍 mmm[i] = arr[i];//若运行这一句,发现内存基本不变 } Console.WriteLine("完成"); Console.ReadLine(); Console.Write 阅读全文
posted @ 2010-09-28 00:27 再快一点 阅读(315) 评论(0) 推荐(0)
摘要:class Program { static void Main(string[] args) { //可以不用在方法名后传入类型 MyClass.Fun(123); //必须要在方法名后传入一个类型 MyClass.Fun2int(); } } class MyClass { public static void FunT(T item) { Console.WriteLine("wq"); } public static void Fun2T() { Console.WriteLine("ly"); } } 阅读全文
posted @ 2010-08-12 18:38 再快一点 阅读(257) 评论(0) 推荐(1)
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;namespace Test{ delegate void MyDelegate(); delegate MyClosure Closure(); class Program { static void Main(string[] args) { Closure clo = new Closure(Fun); MyClosure mm = clo(); mm.Show(); mm.Add(); mm. 阅读全文
posted @ 2010-08-02 14:55 再快一点 阅读(172) 评论(0) 推荐(0)
摘要:第一种:.Net 3.5 代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace 闭包{ class Program { static void Main(string[] args) { ListAction arr = new ListAction(); for (int i = 0; i 3; i++) { arr.Add(()={Console.WriteLine(i);}); } foreach (var item in arr) { 阅读全文
posted @ 2010-08-01 14:39 再快一点 阅读(432) 评论(0) 推荐(0)
摘要:using System;using System.Collections.Generic;using System.Collections;class Program{ static void Main(string[] args) { //第一个例子 //int counter = 0; //IEnumerableint values = Utilities.Generate(10, () = counter++); //Console.WriteLine("Current Counter: {0}", counter); //foreach (int num in values) 阅读全文
posted @ 2010-07-29 09:40 再快一点 阅读(206) 评论(0) 推荐(0)