正文内容加载中...
posted @ 2011-05-26 22:46 dragonpig 阅读 (717) 评论 (0) 编辑
摘要:class Student{ public string Name { get; set; }}static double Test(int loop, Student stu, Func<Student, string> action){ var watch = Stopwatch.StartNew(); string s = null; for (var i = 0; i < loop; i++) s = action(stu); return watch.ElapsedTicks;}static Func<Student, string> NativeGet 阅读全文
posted @ 2011-05-01 00:18 dragonpig 阅读 (1065) 评论 (2) 编辑
摘要:当跨assemblies的时候要特别注意两者的区别, 请看这篇文章if the scope of your constant is limited to just one assembly, class, or smaller (you can define a const inside a method), this is not a big deal. However, if the const is visible outside the assembly it is defined in, we must be wary! Because the const’s value is su 阅读全文
posted @ 2011-03-25 16:48 dragonpig 阅读 (539) 评论 (0) 编辑
摘要:在sqlserver中可以这样显示分组前N个成员, 关键在row_number, partitionselect * from (select schoolmember_id, row_number() over(partition by school_id order by schoolmember_id ) as number from schoolmember) as awhere a.number < 3 阅读全文
posted @ 2011-03-22 18:04 dragonpig 阅读 (206) 评论 (0) 编辑
摘要:private static int BinarySearch(T[] array, int index, int length, T value){ int lo = index; int hi = index + length - 1; while (lo <= hi) { int i = lo + ((hi - lo) >> 1); int order; if (array[i] == null) { order = (value == null) ? 0 : -1; } else { order = array[i].CompareTo(value); } if (o 阅读全文
posted @ 2011-03-08 16:19 dragonpig 阅读 (194) 评论 (0) 编辑
摘要:declare @text nvarchar(500) ,@delimiter nchar(1)set @text = '1,2,3'set @delimiter = ',' set @text = @text + @delimiter;WITH CSV([index], [comma_index])as(select [index] = 1, [comma_index] = CHARINDEX(@delimiter, @text) union allselect [index] = [comma_index] + 1, [comma_index] = CHAR 阅读全文
posted @ 2011-03-02 17:24 dragonpig 阅读 (140) 评论 (0) 编辑
摘要:通过SqlServer的Common Table Expressions (CTE)可以进行递归计算。参见Using Common Table Expressions 和 Recursive Queries Using Common Table Expressions通过CTE计算FibonacciWITH Fib(a, b)AS(SELECT 0,1 UNION allSELECT b, a+b FROM Fib WHERE b < 10)SELECT * FROM Fib 阅读全文
posted @ 2011-03-02 16:48 dragonpig 阅读 (160) 评论 (0) 编辑
摘要:由于最近较忙,上一篇的坑估计要慢慢填了。感觉写文章介绍要比写程序还累啊。先看看测试程序,能够了解api支持哪些功能:static void Main(string[] args){ //wrapper对象 dynamic data = DJson.Wrap(new { name = "Jane", male = false, age = 24, dob = DateTime.Now, friend = new { name = "Jesse", male = true, age = 32, dob = DateTime.Now }, mobile = n 阅读全文
posted @ 2011-02-27 18:39 dragonpig 阅读 (323) 评论 (0) 编辑
摘要:参考 http://www.yoda.arachsys.com/csharp/singleton.html双lock的singleton性能非常差,这里推荐inner class的方式,并且加上泛型。public class Singleton<T> where T : new(){ public static T Instance { get { return Nested.instance; } } private class Nested { //suppress optimization in .net v1.1 static Nested() { } internal s 阅读全文
posted @ 2011-02-27 18:25 dragonpig 阅读 (358) 评论 (0) 编辑
摘要:通过jQuery.get是不能异步访问跨域资源的。主要是因为安全考虑,否则其他域有可能获得当前页的cookie造成隐私泄漏。但js确可以跨域访问,因为所有浏览器都支持refer外部的js文件。访问外部域的js时会发送外部域的cookie,这样在返回的js中就能获取值了。创建两个website,分别叫local.domain1.com和local.domain2.comdomain1中负责set和get本域的cookie,分别为setcookie.aspx和getcookie.aspx//setcookie.aspxpublic partial class SetCookie : System. 阅读全文
posted @ 2011-02-27 18:04 dragonpig 阅读 (2011) 评论 (0) 编辑