摘要:
习惯在C#代码中写str+="xxx";这样代码的请注意啦,如果这种操作是针对单个变量作很多次叠加操作的,很有可能导致性能降低。大家都知道string与StringBuilder的区别,这里就不说了,来看看例子,震撼一下:分别是测试普通字符串进行5w次叠加操作 vs StringBuilder进行5... 阅读全文
摘要:
我们来打造一个简单的专用于json调用的mvc实现,最终会将如下的C#代码暴露给js调用(代码在最后面有下载):public class UserController { public static Json GetUser( [HttpQueryString("x_user")] int userId, [HttpQueryString("msg")] ... 阅读全文
摘要:
用设计模式、AOP能将一个方法/函数包裹起来,并且插入额外的逻辑行为,不过动作比较大,不是很灵活,下面介绍一种链式调用方法来封装的代码,完成后能实现如下的链式调用:public class BO { public bool Add(string msg) { Console.WriteLine("Add"); if (msg == null) throw new Exception(); return true... 阅读全文
摘要:
Until recently, when I write ajax call, always write like below:$.ajax({ type: "post", datatype: "json", url: "someurl", success: function (data) { //some logic }});and repeat everywhere... Until some day: ... 阅读全文
摘要:
考虑到sql server以及c#,最多只能用decimal类型,也就是29位的数字,做了下面这个数字型id生成器:class Program { static void Main(string[] args) { int i = 100000; Timing t = new Timing(); t.Start(); while(i-->0) UniqueIdGenerator.Next(); t.Stop(); ... 阅读全文