在以往很长一段时间内,我一直都不喜欢调试,特别是大项目的时候,我就更加讨厌了。因为在我的头脑里,调试---其实就是设置一个断点,然后F5以下。F5的过程,也是编译的过程。可想而知,那漫长的等待真是一种煎熬。

不喜欢调试,所以我自作聪明,想到了一种解决方案:在需要加断点的地方 Response.Write 对象值。这种弱智式的“调试”持续了好长时间。

后来有一天,我见同事使用“进程调试”的时候,我才明白,原来调试的过程是这么美好!
方法如下:工具-附加进程-选择“w3wp.exe”即可。

然而,这几天我在win7系统上调试一个新的项目时,却发现这种“进程调试”的方法好像不好使了。经过研究才发现,原来进程调试的前提是(web项目):解决方案中的web项目应该以url方式添加(在IIS下选择站点比较方便)。

直到今天才明白这一点,所以记录下来。
posted @ 2009-11-17 22:16 jeky 阅读(68) | 评论 (2)编辑

第一次发现全等(===)这个比较运算符:

 

===     全等(值和类型)

    
<script type="text/javascript">
var x = 5;
document.writeln(x 
== 5);    // true
document.writeln(x == '5');    // true
document.writeln(x === 5);    // true
document.writeln(x === '5');    // false
document.writeln(x != '5'); // false
document.writeln(x !== '5');    // true
</script>
posted @ 2009-04-20 19:27 jeky 阅读(121) | 评论 (1)编辑
★ 协变:

 委托的类型返回值是它所指向函数的返回值得基类.

    private void InitPage()
    {
        HandlerMethod handler1 
= Method1;
        HandlerMethod handler2 
= Method2; // 协变
    }


    
private class Animal { }
    
private class Dog : Animal { }

    
private delegate Animal HandlerMethod();

    
private static Animal Method1() { return null; }
    
private static Dog Method2() { return null; }   

 


★ 逆变:

委托的类型参数是它所指向函数的参数的派生类.

    private void InitPage()
    {
        HandlerMethod handler1 
= Method1;
        HandlerMethod handler2 
= Method2; // 逆变
    }


    
private class Animal { }
    
private class Dog : Animal { }

    
private delegate void HandlerMethod(Dog dog);

    
private static void Method1(Dog dog) { }
    
private static void Method2(Animal animal) { }   


posted @ 2009-04-04 20:51 jeky 阅读(36) | 评论 (1)编辑
    ----- 传统方法
    
    /// <summary>
    /// 判断一个整数是否为偶数。
    /// </summary>
    /// <param name="n">int类型的整数。</param>
    /// <returns></returns>
    public static bool IsEven(int n)
    {
        return n % 2 == 0;
    }
    
    ---- 二进制方法    
    
    在二进制情况下,奇数的最后一位总是1,而偶数的最后一位总是0。
    所以我们现在只要检测数字的最低位是否为0,就可以知道它是不是偶数了。
    如何检测?这个数字和1进行“与运算”,结果为1则是奇数,结果为0则是偶数。
            
    位逻辑与运算将两个运算对象按位进行与运算。与运算的规则:1与1等于1,1与0等于0。
    比如:10010001(二进制)&11110000等于10010000(二进制)。
    

    /// <summary>
    /// 判断一个整数是否为偶数。
    /// </summary>
    /// <param name="n">int类型的整数。</param>
    /// <returns></returns>
    public static bool IsEven(int n)
    {
        return (n & 1) == 0;
    }    
   
posted @ 2009-03-31 21:17 jeky 阅读(103) | 评论 (0)编辑
看图例:



看代码:

    /// <summary>
    
/// 选择排序。
    
/// </summary>
    
/// <param name="arrInt"></param>
    private void Sort(int[] arrInt)
    {
        
// 因为第i个值,需要和i+1之后的值比较,所以这里需要 -1。
        for (int i = 0; i < arrInt.Length - 1; i++)
        {
            
int min = i; // 最小值的位置
            for (int j = i + 1; j < arrInt.Length; j++)
            {
                
if (arrInt[j] < arrInt[min])
                    min 
= j;
            }
            
if(min != i)
            {
                
// 最小值和第i个记录交换
                int temp = arrInt[i];
                arrInt[i] 
= arrInt[min];
                arrInt[min] 
= temp;
            }
        }
    }
posted @ 2009-03-31 20:22 jeky 阅读(142) | 评论 (1)编辑

让我笔试吃亏的题目:单例模式。

因为是纯英文试卷,而且我从来没有用过单例模式。

答题时,有点儿懵了,竟然在类的实例构造函数里瞎写一番。

回来之后,终于静下来心,踏踏实实地学习了一下。记录在此。


1. 单例的目的是什么?  
    这个应该很明显,保证一个类只有单一的实例,也就是说你无法通过New或CreateInstance来创建这个类的一个新实例。    
    
2. 单例的好处在哪里?
    当一个对象在程序内部只能有一个实例的时候,它可以保证我们不会重复创建,而是始终指向同一个对象。    

3. 应用场景:

    如(记录系统日志.log)


4. 参考文章:
    《Implementing the Singleton Pattern in C#》
    http://www.yoda.arachsys.com/csharp/singleton.html

 

simple thread-safety

    // 密封类,不允许派生子类
    public sealed class Singleton
    {
        
static Singleton instance = null// 静态实例
        static readonly object padlock = new object(); // 静态只读锁

        Singleton() { } 
// 私有的构造函数

        
// 公共的静态属性:获取类的实例
        public static Singleton Instance
        {
            
get
            {
                
lock (padlock)
                {
                    
if (instance == null)
                        instance 
= new Singleton();
                }
                
return instance;
            }
        }
    }

 

 

not quite as lazy,

but thread-safe without using locks

    // 密封类,不允许派生子类
    public sealed class Singleton
    {
        
static readonly Singleton instance = new Singleton(); // 静态只读实例

        
static Singleton() { } // 静态构造函数,用于是初始化 instance 变量

        Singleton() { } 
// 实例构造函数

        
// 公共的静态属性:获取类的实例
        public static Singleton Instance
        {
            
get
            {
                
return instance;
            }
        }
    }
posted @ 2009-03-25 17:27 jeky 阅读(140) | 评论 (2)编辑
     摘要: 最近在搞一个网站,需要在内容区域高亮显示一些关键词。本来想在后台页面用c#实现,后来感觉这样做不太可取。因为我想高亮的高键词有n个之多,在服务端循环处理的话,势必会影响效率、占用服务器资源。所以,才考虑使用JS来实现,代码如下:一个小类(可以放置到一个*.js文件中)[代码] 页面调用:[代码]CSS定义(可以设置多种风格,以支持不同类型的关键词):[代码] 结束语: 以上代码在 FF3.0 及 ...  阅读全文
posted @ 2009-03-13 17:03 jeky 阅读(214) | 评论 (4)编辑
     摘要: i,执行大小写不敏感的匹配。g,执行一个全局的匹配。简而言之,就是找到所有的匹配,而不是在找到第一个之后就停止了。  阅读全文
posted @ 2009-03-13 16:42 jeky 阅读(81) | 评论 (0)编辑
     摘要: 正确的:input[type=text] { width:90%; }注意不正确的:input[@type='text'] { width:90%; } 浏览器检测通过:FF3、IE7/8  阅读全文
posted @ 2009-03-11 23:44 jeky 阅读(353) | 评论 (0)编辑