代码改变世界

随笔档案-2008年05月

在.NET程序中正确使用String类型

2008-05-28 18:05 by Vincent.C, 207 阅读, 收藏,
摘要: 在实际程序中,String类型用得非常广泛,然而,由于.NET对String类型变量的独特管理方式,使用不当,会严重影响程序的性能。我们分几个方面来谈这个问题:1 了解String数据的内存分配方式编写一个控制台应用程序,输入以下测试代码: class Program { static void Main(string[] args) { String s = "a"; s = "abcd"; } }使用.NET Framework 2.0 SDK提供的ildasm.exe工具查看生成的MSIL指令:01 .method private hidebysi 阅读全文

Javascript:keyCode键码值表

2008-05-22 13:27 by Vincent.C, 252 阅读, 收藏,
摘要: 按键 键码 按键 键码 按键 键码 按键 键码 A 65 J 74 S 83 1 49 B 66 K 75 T 84 2 50 C 67 L 76 U 85 3 51 D 68 M 77 V 86 4 52 E 69 N 78 W 87 5 53 F 70 O 79 X 88 6 54 G 71 P 80 Y 89 7 55 H 72 Q 81 Z 90 8 56 I 73 R 82 0 48 9 57 数字键盘上的键的键码值(keyCode) 功能键键码值(keyCode) 按键 键码 按键 键码 按键 键码 按键 键码 0 96 8 104 F1 112 F7 118 1 97 9 105 阅读全文

一个重写Page基类的例子

2008-05-22 11:11 by Vincent.C, 247 阅读, 收藏,
摘要: using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;/// <summary>/// BasePage 的摘要说明/// </summary>public class Bas 阅读全文

Url地址重写,利用HttpHander手工编译页面并按需生成静态HTML文件

2008-05-22 10:27 by Vincent.C, 230 阅读, 收藏,
摘要: 作者:武眉博思路:1 挂载“.aspx"的请求到自定义的 Httphander 内2 配置 URL 重写规则3 访问某.aspx 文件时,在 HttpHander 内根据配置确定是否应该生成接着...if(需要生成){ if(若已经生成 html 文件 ) { if(文件并未过期) { 则直接定向(Server.Transfer())。 } else { 删除 HTML 文件; 重新编译.aspx(Page 内数据库操作等等) 生成 HTML 文件; } } else if(尚未生成文件) { 生成 Html。 }}else{ 则编译.aspx 文件}另:建议阅读一下 dudu 的 阅读全文

关于.net 中调用script的alert后 css失效的办法

2008-05-22 10:16 by Vincent.C, 201 阅读, 收藏,
摘要: 最近碰到个问题,平常在aspx页面中使用alert后,页面上的css就失效了 查了下网络,用以下语法即可避免css失效this.RegisterClientScriptBlock("js", "<script>alert('搜藏完毕')</script>"); 阅读全文

通过.NET平台编写和发布简单的Windows Service

2008-05-07 11:19 by Vincent.C, 215 阅读, 收藏,
摘要: 新建一个(VB.NET/C#)项目,选择Windows Service应用..然后在OnStart类里就可以添加代码了. 如果想实现定时运行,活实时监听的功能,可以用.NET 提供的TIMER类. 以下是代码片段. private void theTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (!ExCondition()) { return; } try { theTimer.Enabled = false; MyTransaction(); } catch(Exception es) { WriteL 阅读全文