กิจกรรม
17 มี.ค. 23 - 21 มี.ค. 23
แอปอัจฉริยะ เข้าร่วมชุด meetup เพื่อสร้างโซลูชัน AI ที่ปรับขนาดได้ตามกรณีการใช้งานจริงกับนักพัฒนาและผู้เชี่ยวชาญร่วมกัน
ลงทะเบียนตอนนี้เบราว์เซอร์นี้ไม่ได้รับการสนับสนุนอีกต่อไป
อัปเกรดเป็น Microsoft Edge เพื่อใช้ประโยชน์จากคุณลักษณะล่าสุด เช่น การอัปเดตความปลอดภัยและการสนับสนุนด้านเทคนิค
Possibly incorrect assignment to local 'variable' which is the argument to a using or lock statement. The Dispose call or unlocking will happen on the original value of the local.
There are several scenarios where using
or lock
blocks will result in a temporary leak of resources. Here is one example:
thisType f = null;
using (f)
{
f = new thisType();
...
}
In this case, the original value, such as null, of the variable thisType
will be disposed of when the using
block finishes executing, but the thisType
object created inside the block will not be, although it will eventually get garbage collected.
To resolve this error, use the following form:
using (thisType f = new thisType())
{
...
}
In this case, the newly allocated thisType
object will be disposed of.
The following code will generate warning CS0728.
// CS0728.cs
using System;
public class ValidBase : IDisposable
{
public void Dispose() { }
}
public class Logger
{
public static void dummy()
{
ValidBase vb = null;
using (vb)
{
vb = null; // CS0728
}
vb = null;
}
public static void Main() { }
}
คำติชม .NET
.NET เป็นโครงการโอเพนซอร์ส เลือกลิงก์เพื่อให้คำติชม:
กิจกรรม
17 มี.ค. 23 - 21 มี.ค. 23
แอปอัจฉริยะ เข้าร่วมชุด meetup เพื่อสร้างโซลูชัน AI ที่ปรับขนาดได้ตามกรณีการใช้งานจริงกับนักพัฒนาและผู้เชี่ยวชาญร่วมกัน
ลงทะเบียนตอนนี้