C#小知識摘撿(後期再慢慢學習)

來源:互聯網
上載者:User

標籤:

(雜湊表的 Map 介面的實現與雜湊表區別)HashMap與HashTable的區別

1.hashMap去掉了HashTable 的contains方法,但是加上了containsValue()和containsKey()方法。
2.hashTable同步的,而HashMap是非同步的,效率上逼hashTable要高。
3.hashMap允許空索引值,而hashTable不允許。

 

Hashtable 內的每一組對象就是一個DictionaryEntry 

例如我們要迴圈hashtable擷取裡面的內容時
foreach (DictionaryEntry de in myHashtable) {...}

 

預存程序:

什麼是預存程序:預存程序就是固化在SQL資料庫系統內部的SQL語句,這樣做的好處是可以提高執行效率、提高資料庫的安全性、減少網路流量。

下面是範例程式碼,可以清晰的get到預存程序的概念

  1. string strsql = "Data Source=192.168.24.53;Initial Catalog=JF_Charging_System;Persist Security Info=True;User ID=sa;Password=1";//資料庫連結字串  
  2. string sql = "myinsert";//要調用的預存程序名  
  3. SqlConnection conStr = new SqlConnection(strsql);//SQL資料庫連接對象,以資料庫連結字串為參數  
  4. SqlCommand comStr = new SqlCommand(sql, conStr);//SQL語句執行對象,第一個參數是要執行的語句,第二個是資料庫連接對象  
  5. comStr.CommandType = CommandType.StoredProcedure;//因為要使用的是預存程序,所以設定執行類型為預存程序  
  6. //依次設定預存程序的參數  
  7. comStr.Parameters.Add("@username", SqlDbType.VarChar, 10).Value = "11";  
  8. comStr.Parameters.Add("@password", SqlDbType.VarChar, 10).Value = "11";  
  9. comStr.Parameters.Add("@name", SqlDbType.VarChar, 10).Value = "11";  
  10. comStr.Parameters.Add("@usertype", SqlDbType.VarChar, 10).Value = "11";  
  11. comStr.Parameters.Add("@createpeople", SqlDbType.VarChar, 10).Value = "11";  
  12. conStr.Open();//開啟資料庫連接  
  13. MessageBox.Show(comStr.ExecuteNonQuery().ToString());//執行預存程序  
  14. conStr.Close();//關閉串連  

 

在避免裝箱操作中,使用.Tostring()可以避免裝箱;

C#小知識摘撿(後期再慢慢學習)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.