Feeds:
文章
留言

Archive for 六月 14th, 2006

 
1. 使用整數以外的型別作為索引子
先入為主的觀念使我以為只能以整數型態來建構 Indexer,原來並非如此,下面是一個非字串 Index 的範例
using System;
using System.Collections.Generic; 
namespace ConsoleApplication1 {
    class CB {
        Dictionary<string, int> tblSex;
        public CB(){
            tblSex = new Dictionary<string, int>();
            tblSex.Add("Arick", 1);
            tblSex.Add("Mavis", 0);
        }
        public int this[string name]{
            get {
                if (tblSex.ContainsKey(name)) {
                    return tblSex[name];
                } else {
                    return -1;
                }
            }
        }
        public int this[KeyValuePair<string, int> kp]{
            get {
                return kp.Value;
            }
        }
        public static void Test() {
            CB a = new CB();
            Console.WriteLine(a["Arick"]); // 1
            Console.WriteLine(a["Mavis"]); // 0
            Console.WriteLine(a["Unknown"]); // -1
            Console.WriteLine(a[ new KeyValuePair<string,int>("KeyField",99) ]); // 99
        }
    }
    class Program {
        static void Main(string[] args) {
            CB.Test();
        }
    }
}
2. Indexer 的參數可以多於一個(不過我還沒想到應用場合),如下範例
using System;
namespace ConsoleApplication1 {
    class CB {
        public string this[string v1, int v2] {
            get {
                return string.Format("{0}=>{1}", v1, v2);
            }
        }
        public static void Test() {
            CB a = new CB();
            Console.WriteLine(a["Arick", 1]); // Arick=>1
        }
    }
    class Program {
        static void Main(string[] args) {
            CB.Test();
        }
    }
}

Read Full Post »

今天看了 Effective C# 才發現 C#2.0 的屬性可以這樣用 ^O^
 
using System;
namespace ConsoleApplication1 {
    class CA {
        public CA(string v) {
            Prop = v; // 使用 Prop 的 set
        }
        private string prop = null;
        public string Prop {
            // public
            get {
                return prop;
            }
            // private
            private set {
                prop = value;
            }
        }
    }
    class Program {
        static void Main(string[] args) {
            CA a = new CA("Arick");
            Console.WriteLine(a.Prop); // Arick
            a.Prop = "Mavis"; // Error: The property or indexer ‘ConsoleApplication1.CA.Prop’ cannot be used in this context because the set accessor is inaccessible
        }
    }
}

Read Full Post »

摘要:
1. Google線上付款機制Gbuy預計6月28日推出
2.  Gbuy預計初期免費使用,但之後商家會被收取每筆成交費用的1.5%至2%交易費
3.  使用者點選商家的Gbuy功能後,Google就可開始蒐集資料,消費者之後則會被導至Google的Gbuy網站來完成交易。(這個功能不錯,可以分析使用者的消費習慣,並整合顯有的廣告機制)

 

ps. Gbuy … 確實很像台語的髒話 -_-b

 

相關參考:

[1] http://taiwan.cnet.com/news/software/0,2000064574,20107089,00.htm  

[2] http://news.mydrivers.com/pages/20060320140438_59821.htm

[3] http://tech.163.com/06/0611/10/2JB252I9000915BF.html

[4] http://www.informationweek.com.cn/article_topictypeid_85_articleid_1052_sectopictypeid_999.html

Read Full Post »