zoukankan      html  css  js  c++  java
  • hashtable的一个使用

    在开发食神软件,前台管理的点菜界面中,需要用到for循环动态生成各种菜的按钮和各种口味的按钮,而动态生成的按钮只有四个属性,而每一种菜和口味还有很多字段是下面还需要用到的!这时一可以给按钮加多需要的属性,二是建立hashtable表,把需要的属性组织封装到表中,并把表付给按钮的tag属性,代码如下:

                            Hashtable ht = new Hashtable();
                            ht.Add("KindNo", dsfood.Tables[0].Rows[j]["KindNo"].ToString());
                            ht.Add("CanFree", bool.Parse(dsfood.Tables[0].Rows[j]["CanFree"].ToString()));
                            ht.Add("CanDisc", bool.Parse(dsfood.Tables[0].Rows[j]["CanDisc"].ToString()));
                            ht.Add("IsService", bool.Parse(dsfood.Tables[0].Rows[j]["IsService"].ToString()));
                            ht.Add("IsSumPrnt", bool.Parse(dsfood.Tables[0].Rows[j]["IsSumPrnt"].ToString()));
                            ht.Add("IsPrint", bool.Parse(dsfood.Tables[0].Rows[j]["IsPrint"].ToString()));
                            ht.Add("IsLocal", bool.Parse(dsfood.Tables[0].Rows[j]["IsLocal"].ToString()));
                            ht.Add("IsCurrPrice", bool.Parse(dsfood.Tables[0].Rows[j]["IsCurrPrice"].ToString()));
                            ht.Add("Limited", int.Parse(dsfood.Tables[0].Rows[j]["Limited"].ToString()));

                            b[j].Tag = ht;//Tag属性选中的表

    在下面需要用到的菜的属性时:

      Hashtable ht2 = b.Tag as Hashtable;  //解压表
                        limited = (int)ht2["Limited"]; //获得总的扣炖量  

                        model.KindNo = (string)ht2["KindNo"];
                        model.OrderEmpID = 149;
                        model.amt = model.Prise * model.qty;
                        model.CancelQty = 0;
                        model.IsFree = (bool)ht2["CanFree"];
                        model.FreeQty = 0;
                        model.IsDisc = (bool)ht2["CanDisc"];
                        model.IsServ = (bool)ht2["IsService"];
                        model.TotalAmt = model.Prise * model.qty;
                        model.IsSumPrnt = (bool)ht2["IsSumPrnt"];
                        model.IsPrint = (bool)ht2["IsPrint"];
                        model.IsLocal = (bool)ht2["IsLocal"];

    哈希表是一个元素<j键(key),值(value)对的集合>每个元素都是存储在Dictionnary对象中的键/值对,键不能为空引用null,但是值可以为null

    在需要存储具有键/值对属性的数据时,例如<学好,学生对象>等具有一一对应关系的数据时,常常需要使用哈希表

  • 相关阅读:
    faster with MyISAM tables than with InnoDB or NDB tables
    w-BIG TABLE 1-toSMALLtable @-toMEMORY
    Indexing and Hashing
    MEMORY Storage Engine MEMORY Tables TEMPORARY TABLE max_heap_table_size
    controlling the variance of request response times and not just worrying about maximizing queries per second
    Variance
    Population Mean
    12.162s 1805.867s
    situations where MyISAM will be faster than InnoDB
    1920.154s 0.309s 30817
  • 原文地址:https://www.cnblogs.com/zhang123/p/2809413.html
Copyright © 2011-2022 走看看