C#中“使用”的用途是什么?用戶(hù)科科斯奇妙的回答C#的隱藏特征問(wèn)題通過(guò)提及using關(guān)鍵詞。你能詳細(xì)說(shuō)明一下嗎?.的用途是什么?using?
3 回答

溫溫醬
TA貢獻(xiàn)1752條經(jīng)驗(yàn) 獲得超4個(gè)贊
using
using (MyResource myRes = new MyResource()){ myRes.DoSomething();}
{ // Limits scope of myRes MyResource myRes= new MyResource(); try { myRes.DoSomething(); } finally { // Check for a null resource. if (myRes != null) // Call the object's Dispose method. ((IDisposable)myRes).Dispose(); }}

一只斗牛犬
TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超2個(gè)贊
using (System.IO.StreamReader r = new System.IO.StreamReader(""))using (System.IO.StreamReader r2 = new System.IO.StreamReader("")) { //code}
using (System.IO.StreamReader r = new System.IO.StreamReader(""), r2 = new System.IO.StreamReader("")) { //code}

森欄
TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個(gè)贊
using (var conn = new SqlConnection("connection string")){ conn.Open(); // Execute SQL statement here on the connection you created}
SqlConnection
.Close()
try
/catch
/finally
.
- 3 回答
- 0 關(guān)注
- 614 瀏覽
添加回答
舉報(bào)
0/150
提交
取消