将var数据转换为哈希表

时间:2011-05-09 10:02:49

标签: linq-to-sql

是否可以将var数据转换为哈希表?

Hashtable hsTest = new Hashtable();
        var oFeat = (from t in db.test
                     where t.Product_ID == iProductID
                     select t);

1 个答案:

答案 0 :(得分:1)

假设您希望将Product_ID用作哈希表中的键,并将Product_Name用作值。你可以这样做:

Hashtable hsTest = new Hashtable ();
var oFeat = (from t in db.test
             where t.Product_ID == iProductID
             select t);
foreach (var product in oFeat) {
    hsTest[product.Product_ID] = product.Product_Name;
}