C#中“使用”的用途是什么?用户科科斯奇妙的回答C#的隐藏特征问题通过提及using关键词。你能详细说明一下吗?.的用途是什么?using?
3 回答
温温酱
TA贡献1752条经验 获得超4个赞
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贡献1784条经验 获得超2个赞
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贡献1810条经验 获得超5个赞
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 关注
- 589 浏览
添加回答
举报
0/150
提交
取消